The simplest way to disable ajax caching is to generate a random number directly on the js end, but sometimes this method is not applicable to post, what should we do if we want to disable the ajax cache for post-submitted data? below I have sorted out a lot about prohibiting aja... the simplest way to disable ajax caching is to generate a random number directly on the js end, but sometimes this method is not applicable to post, what should we do if we want to disable the ajax cache for post-submitted data? I have sorted out a lot of examples about disabling ajax cache.
Ajax cache is good, but it also has some disadvantages. caching sometimes leads to misoperations and affects user experience. if your WEB project does not require ajax caching, you can disable ajax caching in the following ways.
1. disable ajax caching in ASP:'At the beginning of an ASP webpage, the code is as follows:
Response.expires=0 Response.addHeader("pragma","no-cache") Response.addHeader("Cache-Control","no-cache, must-revalidate")
2. disable Ajax caching in PHP, At the beginning of the PHP web page, the code is as follows:
header("Expires: Thu, 01 Jan 1970 00:00:01 GMT"); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache");
3. disable ajax caching in JSp,The code is as follows:
// Put it at the beginning of the JSP page, response. addHeader ("Cache-Control", "no-cache"); response. addHeader ("Expires", "Thu, 01 Jan 1970 00:00:01 GMT ");
4. Force update by adding random characters to the webpageThe code is as follows:
var url = 'http://url/'; url += '?temp=' + new Date().getTime(); url += '?temp=' + Math.random();
5. for static HTML, you can add an HTTP headers header to disable caching. the code is as follows:
6. add the following code to prohibit ajax caching before XMLHttpRequest sends a request. the code is as follows:
XMLHttpRequest.setRequestHeader("If-Modified-Since","0"); XMLHttpRequest.send(null);
VII. jQuery ajax Load disabled
JQuery provides a method to prevent ajax from using the cache. add the following statement to the javascript file of the head to solve the problem. The code is as follows:
$. AjaxSetup ({cache: false // disable the corresponding AJAX cache });
Summary:But now jquery ajax is used. if you do not want to cache, you can directly set cache: false to solve the problem of post, get, and other data submission methods.
Article address:
Reprint at will ^ please include the address of this article!