Ajax|ajax Source | sample | Application Example 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 isXMLHttpRequest. 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 (test.htm):
<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"/>
<div id= "message" > Please try to enter my QQ number: 178010108, you will see the detailed information returned .</div>
Server-side program code (demo2.asp):
<%
Response.ContentType = "Text/xml"
Response.Charset = "GB2312"
If Request ("QQ") = "178010108" Then
Response.Write "178010108| Arisisi | ASP technology, Welcome to visit <a href=www.alixixi.com> Arisisi </a> "
Else
Response.Write "This QQ number is the empty number Oh"
End If
%>