Ajax parameters in jquery detailed description
Name of parameter |
Type |
Describe |
Url |
String |
(Default: Current page address) sends the requested address. |
Type |
String |
(Default: "Get") The Request method ("POST" or "get"), the default is "get". Note: Other HTTP request methods, such as PUT and DELETE, can also be used, but only some browsers support it. |
Timeout |
Number |
Sets the request time-out (in milliseconds). This setting overrides the global settings. |
Async |
Boolean |
(default: TRUE) by default, all requests are asynchronous requests. If you need to send a synchronization request, set this option to false. Note that the sync request will lock the browser, and the user's other actions must wait for the request to complete before it can be executed. |
Beforesend |
Function |
You can modify the functions of the XMLHttpRequest object before sending the request, such as adding a custom HTTP header. The XMLHttpRequest object is the only parameter. |
function (XMLHttpRequest) { This The options for this AJAX request } |
Cache |
Boolean |
(default: TRUE) JQuery 1.2 new feature, set to False will not load the request information from the browser cache. |
Complete |
Function |
The callback function after the request completes (called when the request succeeds or fails). Parameters: XMLHttpRequest Object, Success information string. |
function (XMLHttpRequest, textstatus) { This The options for this AJAX request } |
ContentType |
String |
(Default: "application/x-www-form-urlencoded") the content encoding type when sending information to the server. The default values are suitable for most applications. |
Data |
Object, String |
Data sent to the server. is automatically converted to the request string format. The GET request will be appended to the URL. View the ProcessData option description to disallow this automatic conversion. Must be a key/value format. If an array, JQuery automatically corresponds to the same name for the different values. such as {foo:["bar1", "Bar2"]} converted to ' &foo=bar1&foo=bar2 '. |
DataType |
String |
Expected data type returned by the server. If not specified, JQuery automatically returns Responsexml or ResponseText based on the HTTP packet MIME information and is passed as a callback function parameter, with the available values: "XML": Returns an XML document that can be processed with jQuery. HTML: Returns plain text HTML information, including the script element. "Script": Returns plain text JavaScript code. Results are not automatically cached. "JSON": Returns the JSON data. "JSONP": Jsonp format. When calling a function using JSONP form, such as "myurl?callback=?" JQuery is automatically replaced? is the correct function name to execute the callback function. |
Error |
Function |
(Default: This method is called when a request for automatic judgment (XML or HTML) fails.) This method has three parameters: the XMLHttpRequest object, the error message, and (possibly) the error object being captured. |
function (XMLHttpRequest, textstatus, Errorthrown) { Typically, Textstatus and Errorthown have only one of the values This The options for this AJAX request } |
Global |
Boolean |
(default: TRUE) whether to trigger global AJAX events. Setting to FALSE will not trigger global AJAX events, such as Ajaxstart or Ajaxstop. Can be used to control different AJAX events |
Ifmodified |
Boolean |
(default: false) to get new data only when the server data changes. Use the HTTP packet last-modified header information to determine. |
ProcessData |
Boolean |
(default: TRUE) by default, the sent data is converted to an object (technically not a string) to match the default content type "application/x-www-form-urlencoded". Set to False if you want to send DOM tree information or other information that you do not want to convert. |
Success |
Function |
The callback function after the request succeeds. This method has two parameters: the server returns data, returns the status |
function (data, textstatus) { Data could be xmldoc, jsonobj, HTML, text, etc ... This The options for this AJAX request } |
$ (document). Ready (function() {JQuery ("#clearCac"). Click (function() {jquery.ajax ({URL:"/handle/do.aspx", type:"POST", data: {ID:' 0 '}, DataType:"JSON", Success:function(msg) {alert (msg); }, Error:function(XMLHttpRequest, Textstatus, Errorthrown) {alert (xmlhttprequest.status); alert (xmlhttprequest.readystate); alert (textstatus); }, Complete:function(XMLHttpRequest, textstatus) { This;//options parameters passed when calling this Ajax request } }); }); });
I. Error:function (XMLHttpRequest, Textstatus, Errorthrown)
(Default: Automatically determine (XML or HTML) the call time when a request fails. The parameters have the following three: XMLHttpRequest object, error message, and (optionally) the error object being captured. If an error occurs, the error message (the second argument ) may also be "timeout", "error", "Notmodified", and "ParserError", in addition to being null.
Textstatus: "Timeout", "error", "Notmodified" and "ParserError".
Second, the first parameter returned by the error event XMLHttpRequest has some useful information:
Xmlhttprequest.readystate:
Status code:
0-(uninitialized) has not yet called the Send () method
1-(load) called the Send () method, sending the request
2-(loading complete) the Send () method executes and has received the full response content
3-(interactive) parsing response content
4-(complete) The response content resolution is complete and can be invoked on the client
Third,data: "{}", the data is empty also must pass "{}"; otherwise the return is in XML format. and prompt ParserError.
There is also a relationship between the ParserError and header types. and coded header (' content-type:text/html; Charset=utf8 ');
Ajax parameters in jquery are described in detail