XMLHttpRequest. open (); what is the difference between the first parameter post and get? When to select and what is the difference between other parameters?
Get and post are two methods for sending requests from clients in HTML to the server. They can also be called two methods for transmitting data between pages, these two are the most common)
Get transfers data through the URL, which is the last part of the address bar, and transmits the URL to the server.
In post mode, the data in form is stored in the header of the HTML stream.
The methods for obtaining their values are also different.
The former is obtained using request. querystring [].
The latter is obtained using request. Get.
Generally, a small amount of non-sensitive data is transmitted through get, but the URL length is limited to 225 characters. Therefore, if there are too many data, post is used for transmission ,,, if you have more data here, you can use XML to transmit data. The transfer and acquisition methods are the same as described above !!
XMLHttpRequest. Open (bstrmethod, bstrurl, varasync, bstruser, bstrpassword)
Open creates a new HTTP request and specifies the request method, URL, and authentication information.
Syntax
Oxmlhttprequest. Open (bstrmethod, bstrurl, varasync, bstruser, bstrpassword );
Parameters
Bstrmethod
HTTP methods, such as post, get, put, and PROPFIND. Case Insensitive.
Bstrurl
The requested URL address, which can be an absolute or relative address.
Varasync [Optional]
Boolean: Specifies whether the request is asynchronous. The default value is true. If it is true, the callback function specified by the onreadystatechange attribute is called when the status changes.
Bstruser [Optional]
If the server needs to be verified, the user name is specified here. If not, the verification window is displayed when the server needs to be verified.
Bstrpassword [Optional]
The password section in the verification information. If the user name is empty, this value is ignored.
Example
The following example shows how to request book. XML from the server and display the book field.
VaR XMLHTTP = new activexobject ("msxml2.xmlhttp. 3.0 ");
XMLHTTP. Open ("get", "http: // localhost/books. xml", false );
XMLHTTP. Send ();
VaR book = XMLHTTP. responsexml. selectsinglenode ("// book [@ ID = ''bk101''] ");
Alert (book. XML );
Remarks
After calling this method, you can call the send method to send data to the server.