Quick Reference
The .ajaxSetup() method sets default values for future AJAX requests.
<!-- html element to place output -->
<p id="my_output"></p>
// on button click get some info and if successful place it in the HTML element
$('button').click(function() {
$.ajaxSetup({
url: 'test.txt',
success: function(result) {
$('#my_output').html(result);
}
});
$.ajax();
});
Syntax
$.ajaxSetup({name:value, name:value, ... })
Note
It is generally good practice to place your jQuery code/function inside the document load function so that the action takes place ONLY after the document has finished loading. This ensures that all of the page elements that you may be selecting are in place before running the code on them.
Name/Value Pairs
Name | Value/Description |
---|---|
async | A Boolean value indicating whether the request should be handled asynchronous or not (default is true) |
beforeSend(xhr) | A function to run before the request is sent |
cache | A Boolean value indicating whether the browser should cache the requested pages (default is true) |
complete(xhr,status) | A function to run when the request is finished (after success and error functions) |
contentType | The content type used when sending data to the server. (default is: "application/x-www-form-urlencoded") |
context | Specifies the "this" value for all AJAX related callback functions |
data | Specifies data to be sent to the server |
dataFilter(data,type) | A function used to handle the raw response data of the XMLHttpRequest |
dataType | The data type expected of the server response. |
error(xhr,status,error) | A function to run if the request fails. |
global | A Boolean value specifying whether or not to trigger global AJAX event handles for the request (default is true) |
ifModified | A Boolean value specifying whether a request is only successful if the response has changed since the last request (default is false) |
jsonp | A string overriding the callback function in a jsonp request |
jsonpCallback | Specifies a name for the callback function in a jsonp request |
password | Specifies a password to be used in an HTTP access authentication request |
processData | A Boolean value specifying whether or not data sent with the request should be transformed into a query string (default is true) |
scriptCharset | Specifies the charset for the request |
success(result,status,xhr) | A function to be run when the request succeeds |
timeout | The local timeout (in milliseconds) for the request |
traditional | A Boolean value specifying whether or not to use the traditional style of param serialization |
type | Specifies the type of request (GET or POST) |
url | Specifies the URL to send the request to (default is the current page) |
username | Specifies a username to be used in an HTTP access authentication request |
xhr | A function used for creating the XMLHttpRequest object |
jQuery Notes:
- To use jQuery on your site, it must first be downloaded from the official jQuery site and linked to in your document <head>, or linked to via a CDN in your document <head>
- It is generally good practice to place your jQuery code/function inside the document load function so that the action takes place ONLY after the document has finished loading
- When using jQuery, single or double quotation marks are acceptable and work identically to one another; choose whichever you prefer, and stay consistent
We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.