Document directory
The following is an excerpt from W3C, where ParametersMethodThe description is very short, not very understandable, so I found some information to supplement it. This section contains parentheses.
XMLHttpRequest. open ()
Initialize HTTP Request Parameters
Syntax
Open(Method, URL, async, username, password)
MethodThe parameter is the HTTP Method Used for the request. Values include get, post, and head.
(
Case Insensitive.
Post: send data in the "Post" mode, which can be 4 MB in size
Get: send data in the "get" method, only KB
If the request uses the POST method with parameters, the POST method places the parameters in the hidden control of the page.
No parameter. Use the get method.
It is recommended that the requested page be changed midway through the POST method.
)
URLA parameter is the request body. Most browsers implement a same-source security policy and require that the URL have the same host name and port as the text containing the script.
AsyncThe parameter indicates that the request should be executed asynchronously. If this parameter is set to false, the request is synchronized, 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 usually requires an onreadystatechange event handle.
UsernameAndPasswordThe parameter is optional and provides authentication qualifications for URL Authorization. If they are specified, they will overwrite any qualifications specified by the URL itself.
Description
This method initializes Request Parameters
The send () method will be used later. It sets readystate to 1 and deletes all previously specified request headers and all previously received response headers,
Set the responsetext, responsexml, status, and statustext parameters to their default values.
When the readystate is 0 (after the XMLHTTPRequest object is created or the abort () method is called) and when the readystate is 4 (when the response has been received ),
It is safe to call this method.
When called for any other status, the action 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.
Note that when this method is called, The implementation usually does not open a network connection to the web server.
Example
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'; // URL parameters
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 );