Ajax| page
Ajax page Tip Processing
Phenomenon: Because the existing system must be implemented in B/s real-time data display and tip display, when the mouse moved to a
, the system uses AJAX way to the background data. In the process of fetching data, it is often found that the system process pauses, the main performance is: All system process pauses, mouse does not work.
Reason:
The original system adopted a synchronous way to submit, the code is as follows:
var xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");
xmlHTTP. Open ("Post", "testto.jsp", false);/sync
xmlHTTP. Send (DOC);
return xmlhttp.responsetext;
Change the above request to asynchronous, namely the XMLHTTP. Open ("Post", "testto.jsp", true), and a JavaScript script error occurs.
Solution:
var xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");
xmlHTTP. Open ("Post", "maptipto.jsp", true);
xmlHTTP. Send (DOC);
Xmlhttp.onreadystatechange=function () {//callback function
if (xmlhttp.readystate==4&&) {
if (xmlhttp.status==200) {
var text = Xmlhttp.responsetext;
Todo handler function
Dosometing ();
} else {
Alert ("You are requesting an exception.) ");
}
} else{
Prompt function
document.getElementById ("Messagediv"). Innerhtml= "Read the data, please wait ...";
}
}
Note: Process the request in the form of a callback function. The handler function should be placed inside the callback function and should not be placed outside the callback function