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

Source: Internet
Author: User
Tags http request

The following is an excerpt from the world's consortium, where the parameter method is short and not very well understood, so there is some additional information to be found. The bracketed part of the text.

Xmlhttprequest.open ()

Initializing HTTP Request Parameters

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

method Parameters are HTTP methods for the request. Values include get, POST, and head.

(not sensitive to case.)

Post: Send the data in "post" mode, can be as large as 4MB
Get: Send data in "Get" mode, only 256KB
If you request a practical post method with parameters, the Post method places the parameters inside the hidden control of the page
No parameters using Get method
It is also best to post a page that may change in the middle of the request

)

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

The async parameter indicates that the request usage should be performed asynchronously. If this argument is false, the request is synchronized, and subsequent calls to send () will block until the response is fully received.

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

The username and password parameters are optional and are qualified 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, deletes all previously specified headers, and all response headers previously received,

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

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

It is safe to call this method.

When invoked against any other state, the behavior of the open () method is 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.

Be particularly aware that implementations typically do not open a network connection to a WEB server when this method is invoked.

examples

1 synchronous 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 Asynchronous mode

var sendstr= '? a=1&b=2 '; The 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);

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.