Ajax caching is good, but also bad, caching can sometimes lead to misoperation, affect the user experience, if your Web project does not require AJAX caching capabilities, you can use the following methods to prevent Ajax caching.
I. Disable AJAX caching in asp:
' At the beginning of the ASP page
Response.expires=0
Response.AddHeader ("Pragma", "No-cache")
Response.AddHeader ("Cache-control", " No-cache, Must-revalidate ")
Second, in PHP to prevent AJAX caching:
Placed at the beginning of PHP page
header ("Expires:thu, 1970 00:00:01 GMT");
Header ("Cache-control:no-cache, must-revalidate");
Header ("Pragma:no-cache");
Disable AJAX caching in JSP:
Placed at the beginning of the JSP page
response.addheader ("Cache-control", "No-cache");
Response.AddHeader ("Expires", "Thu, 1970 00:00:01 GMT");
forcing updates by adding random characters to a webpage :
var url = ' http://url/';
url = '? temp= ' + New Date (). GetTime ();
url = '? temp= ' + math.random ();
If static HTML, you can add HTTP headers headers to prevent caching, such as:
<meta http-equiv= "Pragma" content= "No-cache"/> <meta http-equiv= "Cache-control" content= "No-cache"
, Must-revalidate "/> <meta http-equiv=" Expires "content=" Thu 1970
GMT "00:00:01/>
http-equiv= "Expires" content= "0"/>
Six, you can prevent Ajax caching by adding the following code before XMLHttpRequest send the request:
Xmlhttprequest.setrequestheader ("If-modified-since", "0");
Xmlhttprequest.send (NULL);
Seven, jQuery Ajax load ban
When jquery provides a way to prevent Ajax from using caching, adding the following statement to the head's JavaScript file can solve the problem.
$.ajaxsetup ({
cache:false//close Ajax corresponding cache
});
Summary, but now it's all using jquery ajax. If we don't want the cache to be set directly, we can solve the cache:false of post, get, and so on.