XMLHttpRequest. open (); what is the difference between the first parameter post and get? When to select and what is the difference between other parameters?

Source: Internet
Author: User
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.

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.