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 ASP web page
The code is as follows: |
Copy code |
Response. expires = 0 Response. addHeader ("pragma", "no-cache ") Response. addHeader ("Cache-Control", "no-cache, must-revalidate ") |
2. Disable Ajax caching in PHP:
The code is as follows: |
Copy code |
// Place it at the beginning of the PHP webpage 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: |
Copy code |
// Place 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 webpage:
The code is as follows: |
Copy code |
Var url = 'http: // url /'; Url + = '? Temp = '+ new Date (). getTime (); Url + = '? Temp = '+ Math. random (); |
5. If it is static HTML, you can add an HTTP headers header to disable caching. For example:
The code is as follows: |
Copy code |
<Meta http-equiv = "pragma" content = "no-cache"/> <Meta http-equiv = "Cache-Control" content = "no-cache, must-revalidate"/> <Meta http-equiv = "expires" content = "Thu, 01 Jan 1970 00:00:01 GMT"/> <Meta http-equiv = "expires" content = "0"/> |
6. You can add the following code to prohibit ajax caching before XMLHttpRequest sends a request:
The code is as follows: |
Copy code |
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. You can solve the problem by adding the following statements to the javascript file of the head.
The code is as follows: |
Copy code |
$. AjaxSetup ({ Cache: false // disable the corresponding AJAX cache }); |
Summary, but now we use jquery + ajax/"target =" _ blank "> jquery ajax. If we don't want to cache, we can directly set cache: false to solve post, get and other data submission methods.