Ajax: Select get or post?

Source: Internet
Author: User

When we do not reload the pageAjaxWhen accessing the server, you have two options to transfer the request information to the server. The two options areGetAndPost.

When sending request information to the server to load a new page, there are two differences between the two options. FirstDifferencesIt is a small part of the information you requested, not the whole page. SecondDifferencesIt is also the most obviousDifferencesBecauseAjaxRequests do not appear in the address bar. Therefore, when a request is sent, there are no similarities or differences on the visitor's screen. UseGetThe generated calls do not expose domains and their values.PostIt will not be exposed. Therefore, how can we choose between them?

A possible mistake for beginners is to use most calls.GetCommand, because this command is relatively easier to write.GetAndPostThe most significant difference between calls is that when a new page loading request is sent,GetCalling has the same limit on the same amount of data. UniqueDifferencesIs a small amountAjaxRequest data, but you do not want to load the page by running this length limit. Beginners may usePost.

When we have a large amount of data to transmit, the best way is to send multiple messages at a time to only transmit a small amount of information.AjaxCall time. If you are usingAjaxCall to send a large amount of data, it is best to end this approach, because this does not save time.

Therefore, we need to transmit a large amount of dataGetAndPostAre you hesitant? Both methods are designed for different purposes, and the difference between the two lies in their purpose. This statement not only appliesGetAndPostIs also applicable to other methods.

GetIs used to obtain information just like its name. It aims to display the information you want to read on the page. Browser BufferGetRequest execution result, if the sameGetWhen the request is sent again, the browser displays the buffered result instead of re-running the entire request. This process is different from the browser processing process, but it is intentionally designed to makeGetMore efficient calls.GetThe call will retrieve the data to be displayed on the page, and the data will not be changed on the server. Therefore, the same results will be obtained when the same data is requested again.

PostThe method should be used to update the server information. If a call needs to change the data stored on the serverPostThe results returned by the call may be completely different, because the secondPostThe call value is different from the first value because some of the values have been updated in the first call.PostA call usually gets a response from the server rather than keeping the buffer of the previous response.

Therefore, do not use the amount of data to decide whether to chooseGetOrPostBut should make a choice between the two based on the purpose. UseGet. If the value to be retrieved changes with time and update processGetAdd a current time parameter to the call so that subsequent calls do not use the previously incorrect buffer. If the call is to send arbitrary data to the server, you can usePost.

In fact, we should not just choose how to use this standard.GetAndPostThe call standard can also be used as the trade-off between the two calls when processing the page processing form.

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.