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.