jQuery.ajaxSetup()function to set the global default settings for Ajax .
This function is used to change the default settings option for AJAX requests in jquery. After all AJAX requests are executed, if the corresponding option parameters are not set, the changed default settings will be used.
The function belongs to the global jQuery object.
Grammar
JQuery 1.1 Adds this static function.
JQuery. Ajaxsetup()
Parameters
| Parameters |
Description |
| Settings |
An object that represents the option to change the default setting for each property, which represents the default value after the change. |
settingsrefer to jQuery.ajax() The settings parameter description in the properties for which the parameter can be recognized. All of the option parameters are optional.
The possible names/values are listed in the following table:
| name |
Value/Description |
| Async |
A Boolean value that indicates whether the request is processed asynchronously. The default is true. |
| Beforesend (xhr) |
The function that is run before the request is sent. |
| Cache |
A Boolean value that indicates whether the browser caches the requested page. The default is true. |
| Complete (xhr,status) |
A function that runs when the request completes (called after the request succeeds or fails, that is, after the success and the error function). |
| ContentType |
The type of content to use when sending data to the server. The default is: "Application/x-www-form-urlencoded". |
| Context |
Specifies the "This" value for all AJAX-related callback functions. |
| Data |
Specifies the data to be sent to the server. |
| Datafilter (data,type) |
A function for handling XMLHttpRequest raw response data. |
| DataType |
The data type of the expected server response. |
| Error (xhr,status,error) |
The function to run if the request fails. |
| Global |
A Boolean value that specifies whether the global AJAX event handler is triggered for the request. The default is true. |
| Ifmodified |
Boolean value that specifies whether the request succeeds only if the response has changed since the last request. The default is False. |
| Jsonp |
A string that overrides the callback function in a JSONP. |
| Jsonpcallback |
Specifies the name of the callback function in a JSONP. |
| Password |
Specifies the password that is used in HTTP access authentication requests. |
| ProcessData |
A Boolean value that specifies whether the data sent through the request is converted to a query string. The default is true. |
| Scriptcharset |
Specifies the requested character set. |
| Success (result,status,xhr) |
The function that is run when the request succeeds. |
| Timeout |
Sets the local request time-out (in milliseconds). |
| Traditional |
A Boolean value that specifies whether to use the traditional style of parameter serialization. |
| Type |
Specifies the type of request (GET or POST). |
| Url |
Specifies the URL to send the request to. The default is the current page. |
| Username |
Specifies the user name to use in HTTP access authentication requests. |
| Xhr |
The function used to create the XMLHttpRequest object.
|
return value
jQuery.ajaxSetup()The function has no return value, or its return value is undefined .
Example & Description
Set global default options for Ajax
$.Ajaxsetup( {
Url: "/index.html" , Default URL
Aysnc: False , Default synchronous loading
Type: "POST" , Use the post mode by default
Headers: { Add request header by default
"Author": "Codeplayer" ,
"Powered-by": "Codeplayer"
} ,
Error: function(Jqxhr,Textstatus,ErrorMsg){ Default handler function On Error
JQXHR is a jquery-encapsulated XMLHttpRequest Object
Textstatus may be: null, "Timeout", "Error", "Abort", or "ParserError"
ErrorMsg may be: "Not Found", "Internal Server Error", etc.
Hint form: Error sending Ajax request to "/index.html" [404]:not Found
Alert( ' send Ajax request to ' + this . URL + ' "error [' + jqxhr. Status + ']: ' + errormsg );
}
} );
$.Ajax( {
Url: "Myurl.php?action=list" ,
Type: "GET" ,
Success: function(Data,Textstatus,Jqxhr){
Alert ( "return Data:" + Data); } ,
Error: function (jqxhr , Textstatus, Errormsg {
Alert ( "own error!" }
Jquery.ajaxsetup ()