This example describes the way Ajax uses error debugging errors in jquery. Share to everyone for your reference. The specific analysis is as follows:
jquery allows us to improve efficiency when developing AJAX applications and reduce many compatibility issues, and we can get the wrong information by capturing the error event in an AJAX project when we encounter an error in the AJAX asynchronous fetch data.
The common usage of Ajax in jquery is similar to:
$ (document). Ready (function () {
jQuery ("#clearCac"). Click (function () {
Jquery.ajax ({
url:url),
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
;// The options parameter to be passed when invoking this Ajax request}});
The success function is invoked when the asynchronous invocation succeeds through Ajax. The success function syntax is:
callback function after successful request. This method has two parameters: Server return data, return status
function (textstatus)
{
///data could be xmldoc, jsonobj, HTML, text, etc ... This
;
The options for this AJAX request
}
The error function is invoked when an error occurs asynchronously through an Ajax call. The error function syntax is:
(Default: Automatic judgment (XML or HTML)) when a request fails to call time.
//parameter has the following three: XMLHttpRequest object, error message, (optional) caught Error object.
//If an error occurs, the error message (the second parameter), in addition to being NULL,
//may also be "timeout", "error", "Notmodified", and "ParserError".
//textstatus: "Timeout", "error", "Notmodified" and "ParserError".
error:function (XMLHttpRequest, Textstatus, Errorthrown)
{
}
The first argument returned by the error event XMLHttpRequest:
Xmlhttprequest.readystate: Meaning of the status code
0-(uninitialized) the Send () method has not been called
1-(load) called Send () method, sending request
2-(load complete) Send () method completed, received all response content
3-(interactive) parsing response content
4-(complete) The response content resolution is complete and can be invoked on the client
Send error may have the following two, or other procedural problems, we need to be careful.
1, data: "{}", data is empty also must pass "{}"; otherwise, the return is in XML format. and prompts ParserError.
2, ParserError of the exception and header type also related. and encoded header (' content-type:text/html; Charset=utf8 ');
I hope this article will help you with your jquery programming.