How to disable ajax caching (ASP/PHP/JSP/html/js)

Source: Internet
Author: User
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!

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.