Simple Ajax example

Source: Internet
Author: User
<SCRIPT type = "text/JavaScript">
VaR XMLHTTP;

// Create an xhr object first

Function createxmlhttprequest (){

// For IE, activexobject
If (window. activexobject ){
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
}

// If other browsers use XMLHttpRequest
Else if (window. XMLHttpRequest ){
XMLHTTP = new XMLHttpRequest ();
}
}

// Start the Function

Function startrequest (){
Createxmlhttprequest ();
// Specify the function to be executed when the readystate attribute changes
XMLHTTP. onreadystatechange = handlestatechange;
// Create an HTTP request and specify the method, URL, and authentication information of the request.
XMLHTTP. Open ("get", "simpleresponse. xml", true );
// Send the request to the HTTP server and receive the response
XMLHTTP. Send (null );
}

Function handlestatechange (){
// 4. The data has been received
If (XMLHTTP. readystate = 4 ){
// 200 the returned Request status is OK
If (XMLHTTP. Status = 200 ){
// In the displayed dialog box, enter the text content of the simpleresponse. xml file.
Alert ("the server replied with:" + XMLHTTP. responsetext );
}
}
}
</SCRIPT>

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.