Getting Started with Ajax---properties and methods of XMLHttpRequest objects

Source: Internet
Author: User
Tags http authentication

The XMLHttpRequest object is unheard of because it is unfamiliar to Ajax. Before you start, learn about its properties and methods to pave the way for its use.          

This article focuses on the properties and methods of XMLHttpRequest. Properties and events for XMLHttpRequest objects




Represents the state of a XMLHttpRequest object [1]


Contains HTTP-appropriate text content that is received by the client [2]


The DOM object corresponding to the XML content of the server response [3]


Server return HTTP status code [4]


The server returns a text message for the status code [5]




This event is triggered when the ReadyState property changes, and is used to trigger the callback function.







Initialization state. The XMLHttpRequest object has been created or has been reset by the Abort () method.



The open () method was invoked, but the Send () method was not invoked. The request has not been sent yet.



The Send () method has been invoked and the HTTP request has been sent to the WEB server. The response was not received.



All response headers have been received. The response body began to receive but did not complete.



The HTTP response has been fully received.

[2]:When readystate=4, ResponseText contains the complete response information.

When readystate=3, ResponseText contains incomplete response information.

When Readystate<3, the ResponseText is an empty string.

[3]: When readystate=4, and the Content-type MIME type of the response head is XML (Text/xml or Application/xml), the attribute has a value and is parsed into an XML document. Other cases are null, including the return of an XML document that is bad or does not complete the response.

[4]: If 200 indicates success, and 404 indicates "NotFound" error. Reading this property when ReadyState is less than 3 results in an exception.

[5]: When the state is 200 it is "OK" and when the state is 404 it is "not Found". As with the Status property, reading this property when ReadyState is less than 3 results in an exception.

Method method of XMLHttpRequest Object

Description: Develop HTTP method with server interaction, URL address and other request information.

Open (Method,url, async, username, password) for initialization

Return value: Gets an object that contains the Send () method

Method: Must be. Used to specify HTTP request methods that support all HTTP methods, such as Get,post, as specified

URI: The address of the requested server, which is automatically parsed into an absolute address.

Async: The request is asynchronous, true means that you are asynchronous, False indicates synchronization, default is True.

Username,password: You can specify the username and password, respectively, and provide the user name and password required by the HTTP authentication mechanism.

After calling open, the readystate state is 1. 

Method 2.send (content) 

Description: Makes a request to the server, and its contents can be DOM objects, input streams, or strings.

After you call the Open method, you can call the Send () method to send the request.

When async=true in Open, the Send () method returns immediately after the call, otherwise it is interrupted until the request returns. 

Method 3.abort ()

The method can suspend a HttpRequest request or HttpResponse reception, and set the XMLHttpRequest state to initialize. 

Method 4.set RequestHeader (Header,value)

This method is used to set the header information for the request.          

This method needs to be invoked after the open method. 

Method 5.getResponseHeader () 

Description: Returns all response header information containing HTTP, where the response header includes content such as Content-length,date,uri.

When Readystate>2, this method retrieves the header information for the response. Otherwise, an empty string is returned.

The getAllResponseHeaders () method returns all HttpResponse header information.

 knowledge of the XMLHttpRequest object, the focus is on how to use the

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.