ajax|xml| Asynchronous
Client file, please modify the file name: test_2.htm
<body>
Examples of XMLHTTP asynchrony:
URL: <input name=a type=textbox value= "test_s.asp" style= "width:600px" >
<input onclick= "GetXML ()" type= "button" value= "Get Source code" >
<input Name=geti type=textbox value= "10000" >
<input onclick= "if (xh && xh.responsetext) {alert (xh.responsetext); Odiv.innerhtml=xh.responsetext}" Typ E= "button" value= "Display source code" >
<div id=m style= "Display:none" ></div>
<script language=javascript>
var odiv
var xh
function GetXML ()
{
Odiv = DOCUMENT.ALL.M;
odiv.innerhtml = "Loading column data, please wait ...." ";
ODiv.style.display = "";
XH = new ActiveXObject ("Microsoft.XMLHTTP")
Xh.onreadystatechange = Getready;
Xh.open ("POST", A.value + "? geti=" + geti.value,true);
Alert ("geti=" + geti.value);
Xh.send ();
}
function Getready ()
{
if (xh.readystate==4)
{
if (xh.status==200)
{
odiv.innerhtml = Xh.responsetext;
odiv.innerhtml = odiv.innerhtml + "Load over"
}
Else
{
odiv.innerhtml = "Sorry, load data failed." Reason: "+ xh.statustext
I tested it, and once it ran too long it would appear: Sorry, loading data failed. Reason: Internal Server Error
But how much is this time? Where to set it?
}
}
Else
{
odiv.innerhtml = "There is already data, but readystate detection failed <br>";
Switch (xh.readystate) {
Case 0:
odiv.innerhtml = odiv.innerhtml + "0 (uninitialized) object has been established, but has not been initialized (the open method has not been invoked)";
Break
Case 1:
odiv.innerhtml = odiv.innerhtml + "1 (initialized) object established, send method not called"
Break
Case 2:
odiv.innerhtml = odiv.innerhtml + "2 (send data) Send method called, but current state and HTTP header unknown"
Break
Case 3:
odiv.innerhtml = odiv.innerhtml + "3 (in data transfer) has received part of the data, because the response and HTTP headers are incomplete, then through Responsebody and ResponseText get part of the data will be error,"
Break
Case 4:
odiv.innerhtml = odiv.innerhtml + "4 (complete) data received, at this time through Responsebody and responsetext to obtain complete response data"
Break
Default
odiv.innerhtml = odiv.innerhtml + xh.readystate + "Unknown state"
Break
}
odiv.innerhtml = odiv.innerhtml + ". Please wait.
}
}
</script>
</body>
Server-side files, please modify the file name: test_s.asp
<%
Dim i
Dim r
Dim t
Dim Lnggeti
Lnggeti=request.querystring ("Geti")
On Error Resume Next
LNGGETI=CLNG (Lnggeti)
If Err<>0 Then
Response.Write "Geterror:not isnumber ()"
Response.End ()
End If
If lnggeti<0 or lnggeti>500000 then
lnggeti=10000
End If
Response.Write "Run Repeat at:" & Lnggeti & "<br>"
T=timer
For I=1 to Lnggeti
R = R & I
If I mod = 0 Then
r= R & "A<br>"
End If
Next
Response.Write "Run Timer:" & CDbl (Timer ()-T) & "<br>"
Response.Write R
%>