This sample mainly demonstrates how to manipulate xmlhttprequest ...
XMLHttpRequest Introduction
To truly realize this magnificent miracle, you must be very familiar with a JavaScript object, that is, XMLHttpRequest. This small object has actually been in several browsers for some time, and it is the core of Web 2.0, Ajax, and most of the rest of this column that will be introduced in the next few months. To give you a quick overview of it, here are a few of the few methods and properties that will be used for that object.
Open (): Creates a new request to the server.
Send (): Sends a request to the server.
Abort (): Exits the current request.
ReadyState: Provides the ready state of the current HTML.
ResponseText: The request response text returned by the server.
Client-side HTML code:
Copy Code code as follows:
<script language= "javascript" type= "Text/javascript" >
var xmlHttp = false;
try {
XmlHttp = new XMLHttpRequest ();
} catch (Trymicrosoft) {
try {
XmlHttp = new ActiveXObject ("Msxml2.xmlhttp");
} catch (Othermicrosoft) {
try {
XmlHttp = new ActiveXObject ("Microsoft.XMLHTTP");
} catch (Failed) {
XmlHttp = false;
}
}
}
if (!xmlhttp)
Alert ("Error initializing xmlhttprequest!");
function GetCustomerInfo () {
var phone = document.getElementById ("QQ"). Value;
var url = "demo2.asp?qq=" + Escape (phone);
Xmlhttp.open ("Get", url, True);
Xmlhttp.onreadystatechange = Updatepage;
Xmlhttp.send (NULL);
}
function Updatepage () {
if (xmlhttp.readystate = = 4) {
if (Xmlhttp.status = = 200) {
var response = XmlHttp.responseText.split ("|");
document.getElementById ("message"). InnerHTML = ' number is: ' + response[0] + ' <br> name is: ' + response[1] + ' <br> sex is: ' + RESPONSE[2] + ' <br> position is: ' + response[3];
Alert ("Response service Complete!");
}
else if (Xmlhttp.status = 404) {
Alert (' requested URL does not exist! ');
}
else {
Alert (' ERROR: Error code: ' + xmlhttp.status);
}
}
}
</script>
<input id= "QQ" type= "text" onchange= "GetCustomerInfo ()"/>
<div id= "message" > Please try to enter my QQ number: 178010108, you will see the detailed information returned .</div>
Server-Side program code:
Copy Code code as follows:
<%
response.contenttype = "Text/xml"
response.charset = "GB2312"
If request ("QQ") = "178010108" then
response.write "178010108| Arisisi | ASP Technology "
Else
response.write " This QQ number is an empty number Oh "
end if
%>