Robust AJAX Source Learning application Example _ajax related

Source: Internet
Author: User
Tags error code
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
%>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.