Native XMLHttpRequest attribute understanding, Ajax (only supports IE7 and later)

Source: Internet
Author: User
Tags xml dom document

To understand Ajax, you must understand the XMLHTTPRequest object and various attributes of this object to build an efficient Ajax application.Program.

Note: xhr objects are used to replace XMLHttpRequest objects.

The. open () method accepts three parameters: the request type, URL address, and Boolean value of asynchronous transmission.

The. Send () method, which accepts a parameter and requests the data sent by the subject. If not, enter null.

. Responsetext method, which responds to the returned text.

. Responsexml method. If the response content type is text/XML application/XML, the xml dom document of the response data is saved.

. Status method, response HTTP status.

. Statustext method, indicating the HTTP status of the response.

If asynchronous transmission is required, the. readystate attribute is required. The readystate attribute, which is described by 0-4.

0: not initialized. The open () method is not called.

1: start. The open () method is called, but the send () method is not called.

2: Send. The send () method is called, but the response is not received.

3: received. Some response data has been received.

4: complete. All response data is received and can be called on the client.

The status attribute also needs to be checked. For the HTTP protocol, we need to know three statuses: 200,300,304.

For the readystate attribute, when its value changes from one value to another, a readystatechange event is triggered to detect the value of readystate after each state change. In the last step, when we start to call the open () method to respond to data, we also need to specify an onreadystatechange event, which is required to start the processing program.

Understand the HTTP header information:

We need to use the setRequestHeader () method to request header information. It receives two parameters, the header field name and the header field value.

We can also use the getResponseHeader () method to pass in the header field name.

We can also use the getallresponseheader () method to obtain a long string containing the header information.

Encoding Problems:

We need encodeuricomponent () for encoding.

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.