Create an XMLHTTPRequest object using Ajax

Source: Internet
Author: User

XMLHttpRequest is used to exchange data with the server in the background. This means that you can update a part of a webpage without reloading the entire webpage.

Create an XMLHTTPRequest object:

VaR XMLHTTP;
If (window. XMLHttpRequest)
{// Code for IE7 +, Firefox, chrome, opera, Safari
XMLHTTP = new XMLHttpRequest ();
}
Else
{// Code for IE6, ie5
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");

}

 

Ajax-send a request to the server:

To send requests to the server, we use the open () and send () Methods of the XMLHTTPRequest object, refer to: http://www.w3school.com.cn/ajax/ajax_xmlhttprequest_send.asp

xmlhttp.open("GET","test1.txt",true); xmlhttp.send();

 

 

Ajax-server response:

To obtain a response from the server, use the responsetext or responsexml attribute of the XMLHTTPRequest object. For details, refer:
Http://www.w3school.com.cn/ajax/ajax_xmlhttprequest_response.asp

Attribute Description
Responsetext Obtain response data in string format.
Responsexml Obtain response data in XML format.

 

 

Ajax-onreadystatechange event

Reference: http://www.w3school.com.cn/ajax/ajax_xmlhttprequest_onreadystatechange.asp

 

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.