This article illustrates an AJAX approach to simple asynchronous communication. Share to everyone for your reference. The specific analysis is as follows:
client: An empty request is issued to the server.
The code is as follows:
Server side: Returns a string directly to the client.
The code is as follows:
Copy Code code as follows:
<%@ Page language= "C #" contenttype= "text/html" responseencoding= "gb2312"%>
<%@ Import namespace= "System.Data"%>
<%
Response.Write ("Successful asynchronous test, very happy");
%>
Question one:
Because IE browsers automatically cache the results of the asynchronous communication, the server's return results are not updated in real time. (But Firefox will refresh normally)
To resolve the cache problem of IE when connecting to the server asynchronously, change the client code as follows:
var surl = "9-1.aspx?" + New Date (). GetTime (); Address constant change
xmlhttp.open ("Get", surl,true);
At the end of the server address to add a current time of the number of milliseconds parameter, so that each request URL address is not the same, thereby deceiving IE browser to solve the IE cache caused by the update problem.
Question two:
When testing the program, if both the client and server side are on the same computer, the asynchronous object returns the current requested HTTP status code = 0, and the client code is changed again as follows:
if (xmlhttp.readystate = = 4 && xmlhttp.status = =)
if (xmlhttp.readystate = 4)
{
if ( Xmlhttp.status = 200 | | STATUS==200 said success!
Xmlhttp.status = = 0)//The status may be 0 when the test is local.
alert ("Server returns:" + Xmlhttp.responsetext);
}
As a result, the final client code is as follows:
I hope this article will help you with your AJAX programming.