Ajax Basics Tutorial (2)-Using the XMLHttpRequest object 2.2 methods and properties

Source: Internet
Author: User
Tags first string http request string methods

Table 2-1 shows some of the typical methods for XMLHttpRequest objects. Don't worry, they will be covered in more detail later.

These methods are discussed in more detail below.

void Open (String methods, String URLs, Boolean asynch, string Username, string password): This method establishes a call to the server. This is a pure scripting method for initializing a request. It has two necessary parameters and 3 optional parameters. To provide a specific method of invocation (get, post, or put), also provides the URL of the invoked resource. You can also pass a Boolean value indicating whether the call is asynchronous or synchronous. The default value is true to indicate that the request is inherently asynchronous. If this argument is false, processing waits until the response is returned from the server. Because asynchronous invocations are one of the main advantages of using AJAX, setting this argument to false is somewhat inconsistent with the intent of using the XMLHttpRequest object. However, as mentioned earlier, it is useful to set this parameter to false in some cases, such as validating the user's input before persisting the page. The last two arguments are self-explanatory, allowing you to specify a specific username and password.

void Send (Content): This method makes a specific request to the server. If the request is declared asynchronous, the method returns immediately, otherwise it waits until the response is received. An optional parameter can be an instance of a DOM object, an input stream, or a string. The content passed into this method is sent as part of the request body.

void setRequestHeader (string header, String value): This method sets the value for a given header in the HTTP request. It has two parameters, the first string represents the header to set, and the second string represents the value to be placed in the header. It needs to be explained that this method must be invoked after calling open ().

Of all these methods, the most likely use is open () and send (). The XMLHttpRequest object also has many properties that are useful when designing Ajax interactions.

void Abort (): As the name suggests, this method is to stop the request.

String getAllResponseHeaders (): The core functionality of this method should be familiar to Web application developers, and it returns a string that contains all the response headers for HTTP requests, including the header, content-

Length, date, and URI.

String getResponseHeader (String header): This method corresponds to getAllResponseHeaders (), but it has a parameter that represents the specified header value you want to get, and returns the value as a string.

In addition to these standard methods, the XMLHttpRequest object also provides a number of properties, as shown in table 2-2. These properties can be used extensively when processing XMLHttpRequest.

Table 2-2 Standard XMLHttpRequest Properties

Back to "Ajax Basics Tutorial-Directory"

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.