Ajax Basics Tutorial (2)-Using the XMLHttpRequest object 2.4 get and post

Source: Internet
Author: User

You might want to know what the difference between get and post is and want to know when to use them. Theoretically, if the request is idempotent, get can be used, and the so-called idempotent means that multiple requests return the same result. In fact, the corresponding server method may modify the state in some way, so this is generally not true. This is just a standard. The more practical difference is in the size of the net charge, and in many cases the browser and the server restrict the URL's length URL to send data to the server. In general, you can use get to fetch data from the server, in other words, to avoid changing the state on the server by using getting calls.

Generally, you should use the Post method when changing the state on the server. Unlike get, you need to set the Content-type header for the Xml-httprequest object, as follows:

xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

Unlike get, post does not limit the size of the net load sent to the server, and the POST request is not guaranteed to be idempotent.

Most of the requests you make may be get requests, but you can also use post if you want.

Back to "Ajax Basics Tutorial-Directory"

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.