Jquery1.8 uses ajax to analyze problems and solutions for calling. jquery1.8ajax
Background: I am working on a project recently to develop a function that uses asp.net DEVELOPMENT AND jquery1.8.0.
In the event triggered by clicking the button, ajax is called to interact with the server, and the callback function follows an error.
Cause analysis:The first thing I think of is that there is a problem with the returned data type, because the json format is very strict in jquery 1.4 and later versions, and must comply with {"target": true, "message ": "success. JSON. stringify () function is used to analyze the response object. The result is correct and the cause is excluded.
Since ajax uses error, I began to analyze the parameters of the error function, including XMLHttpRequest, textStatus, and errorThrown. I found that XMLHttpRequest. status is equal to 0 and XMLHttpRequest. readyState is equal to 0, indicating that the XMLHttpRequest object in the form is not initialized. Next I will study how to initialize the XMLHttpRequest object.
Solution:
var xmlHttpRequest;$(function(){if(window.XMLHttpRequest){xmlHttpRequest=new XMLHttpRequest();}else{xmlHttpRequest=new ActiveXObject("Microsoft.XMLHTTP");}xmlHttpRequest.open("GET","AjaxServlet",true);});
In this way, the problem described above can be solved. Note that normal Ajax access on the PC side will not be affected, because browsers in the PC have built-in XMLHttpRequest objects, but in the middle, this phenomenon occurs, you may need to build and initialize them manually.
Ps: Android browser and IE6 browser ajax request abort error handling
A click event is bound to the page element to trigger ajax requests. In Android browsers and IE6, requests are often interrupted and the Error Type "abort" is returned ", everything works in other browsers.
When I use Fiddler2 and httpWatch in IE6 to monitor requests, "aborted" is often displayed. It's a weekend ,.....
Don't talk nonsense ....
Solution: Add onclick = 'Return false; 'to the tag ;'