Problems encountered in using GET and post in Ajax and solutions _ajax related

Source: Internet
Author: User

Problems with Get encountered:

1. Question one. Caching: When each access URL is the same, the client directly reads the contents of the local cache, even if the background data changes the foreground will not change;

Solution: In? The following link is a num= "random number Math.random ()" or num= "timestamp new Date (). GetTime ()", ' 1.php?username= ' May ' & ' +num (there are no variable names here, avoid conflicts with background parameters)

2. Question two. Garbled, when the transmission of Chinese or special characters, the foreground appears garbled

Solution: Using coded encodeURI (' snail ')

Test results: By using the chrome test, both problems with the result get have been solved

Issues encountered using Post:

Post method, the data is placed in the Send () as a parameter transfer;

Problem: When the request header is not set, the background directly does not process the data, the foreground will not be able to obtain background data returned

Workaround: Manually set the request header (Xhr.setrequestheader (' Content-type ', ' application/x-www-form-urlencoded ')) to declare the data type sent

"Note" Post does not have a caching problem, there is no coding problem (because it has been declared in the request header)

Test results: By using the chrome test, the result post this does not declare the header information, the problem exists

Simply put: The difference between a GET request and a POST request

1. When using a GET request, the parameter is displayed in the URL and the Post method is not displayed

2. Use GET request to send the data quantity is small, the POST request sends the data quantity to be big

The above is a small set to introduce the Ajax in the use of Get and post encountered problems and solutions, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.