Cache Processing Solution for ajax get requests, ajaxget

Source: Internet
Author: User

Cache Processing Solution for ajax get requests, ajaxget

This article describes the cache Processing Solution for ajax get requests. Share it with you for your reference. The specific analysis is as follows:

Most of the time, when Ajax get method is called, the correct data cannot be obtained in time due to cache reasons. Here we will analyze the solution to this problem:

1. Add a random number after the url, for example:Copy codeThe Code is as follows: http://www.test.com? A = a & B = B & r = Math. random ();

2. Add a timestamp after the url:
Copy codeThe Code is as follows: var t = new Date (). getTime ();
Http://www.test.com? A = a & B = B & t = t

3. Use the setRequestHeader function of the XMLHttpRequest object to set the value of If-Modified-Since to 0, as shown in figure
Copy codeThe Code is as follows: xmlHttp. setRequestHeader ('If-Modified-Since ', 0 );

Here we need to understand the meaning of If-Modified-Since.

4. Use the php header Function
Copy codeThe Code is as follows: header ('cache-Control: no-Cache, must-revalidate ');

Set no cache

I hope this article will help you with Ajax programming.

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.