Understanding of XMLHTTP Object methods and Attributes _ basics

Source: Internet
Author: User
1Clients can passXmlHttpObject (msxml2.xmlhttp.3.0) sends a request to the HTTP server and uses the Document Object model(DOM)Handle the response.

1.1 My understanding:

    1. Each operation of the user, there will be data generation.
    2. The DOM or JS is written to encapsulate the data, or the browser itself encapsulates some of the HTTP Protocol's data.
    3. send a request to the HTTP server by XmlHttp some methods of the object, passing in the data parameter .
    4. The returned results are processed through the DOM.

2 members of the XmlHttp object.

2.1 Property

    1. onReadyStateChange: the event handling handle that is triggered when the value of the ReadyState property changes.

Example:xmlhttp.onreadystatechange = Functionhandler;

function Functionhandler () {

if (xmlhttp.readystate = = 4) {

Alert (" pops up this window when the readyState status is 4!!! ");



The handle has only the method name, not the "()" bracket. Pay attention to understanding when assigning values.

    1. ReadyState: This attribute represents the state; there are five states in total:

0 (uninitialized)

Object has been established, but has not yet been initialized (the open method has not been called)

1 (initialization)

Object has been established and the Send method has not been called

2 (send data)

The Send method has been invoked, but the current state and HTTP headers are unknown

3 (in data transfer)

Received part of the data because the response and HTTP headers are not complete, then there will be an error getting some of the data through Responsebody and ResponseText.

4 (complete)

When the data is received, complete response data can be obtained through responsebody and ResponseText

because the xmlHttp is written in a fixed way, each step is accompanied by a state change, so it listens to the event handling handle at all times and executes the corresponding logic.

Code Execution Order:

var xmlhttpreq = new ActiveXObject ("msxml2.xmlhttp.3.0");

Xmlhttpreq.open ("Get", "Http://localhost/test.xml", false);

Xmlhttpreq.send ();

alert (Xmlhttpreq.responsetext);

2.2 Method

    1. Open (method, Url, Syn, User, Password);

When you create a new xmlHttp object, you are actually creating an http request.

This method specifies the mode of the request (Get/post/put/propfind), the URL, the asynchronous ( the default is true), and the authentication information.

When used asynchronously (true) , the callback function specified by the onReadyStateChange property is invoked when the state changes.

    1. Send ();

The way this method is synchronized or asynchronous depends on the S yn parameter in the open method , and if syn = = False, this method will wait for the request to complete or timeout to return if the syn = = TRue, this method will return immediately.

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.