Description of the Open () method parameter of the JavaScript XMLHttpRequest object

Source: Internet
Author: User

Xmlhttprequest.open ()

Initializing HTTP Request Parameters

Grammar
Open
(method, URL, async, username, password)

The method parameter is the HTTP methods used for the request. Values include GET, POST, and HEAD.

(not case sensitive.)

Post: Send data with "POST", can be as large as 4MB
Get: Send data in "Get" mode, only 256KB
If you request a utility post with parameters, the Post method places the parameter inside the hidden control of the page
No arguments using GET mode
The requested page may change in the middle of the way, it is also best to post

)

The URL parameter is the principal of the request. Most browsers implement a homogenous security policy and require the URL to have the same host name and port as the text containing the script.

The Ng>async parameter indicates that the request use should be performed asynchronously. If this parameter is false, the request is synchronous, and subsequent calls to send () will be blocked until the response is fully received.

If this parameter is TRUE or omitted, the request is asynchronous and typically requires a onreadystatechange event handle.

The username and password parameters are optional and provide certification for the authorization required for the URL. If specified, they overwrite any qualifications specified by the URL itself.

Description

This method initializes the request parameters for later use by the Send () method. It sets the readyState to 1, removes all previously specified request headers, and all previously received response headers,

and set the ResponseText, Responsexml, status, and StatusText parameters to their default values.

When ReadyState is 0 (when the XMLHttpRequest object has just been created or the abort () method is called) and when ReadyState is 4 o'clock (the response has been received),

It is safe to call this method.

When invoked against any other state, the open () method behaves as specified.

In addition to saving the request parameters used by the Send () method and resetting the XMLHttpRequest object for reuse, the open () method has no other behavior.

It is important to note that when this implementation typically does not open a network connection to the WEB server.

Example

1 synchronization Mode

var xmlhttp=newxmlhttprequestobj ();

Xmlhttp.open (' Post ', ' XXX.ASP?S=DC ', false);

Xmlhttp.setrequestheader (' Content-type ', ' application/x-www-form-urlencoded ');
Xmlhttp.send (TRUE);

Alert (' Do something ... ')

2 Async Mode

var sendstr= '? a=1&b=2 '; Parameters of the URL

var xmlhttp=newxmlhttprequestobj ();
Xmlhttp.onreadystatechange=function () {
if (xmlhttp.readystate==4) {
if (xmlhttp.status==200) {
alert (Xmlhttp.responsetext);
Other .....
}
}
}
Xmlhttp.open (' Post ', ' xxx.asp ', true);
Xmlhttp.setrequestheader (' Content-type ', ' application/x-www-form-urlencoded ');
Xmlhttp.send (SENDSTR);

Description of the Open () method parameter of the JavaScript XMLHttpRequest object

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.