Summary of Solutions to Ajax cache problems, and ajax cache Summary

Source: Internet
Author: User

Summary of Solutions to Ajax cache problems, and ajax cache Summary

1. Add anyAjaxObj. setRequestHeader ("If-Modified-Since", "0") before ajax sends a request ").

2. Add anyAjaxObj. setRequestHeader ("Cache-Control", "no-cache") before ajax sends a request ").

3. Add a random number after the URL: "fresh =" + Math. random ();.

4. Add the time after the URL: "nowtime =" + new Date (). getTime ();.

5. If jQuery is used, you can directly set $. ajaxSetup ({cache: false }). In this way, all the ajax operations on the page will execute this statement without the need to save cache records.


AJAX cache in IE

If AJAX is not used in combination with Web Services, it simply reads another page, which is the same effect for another page to be opened directly from a browser, therefore, your problem has nothing to do with the AJAX method itself, because AJAX is only responsible for reading. As for what the page provides to him, you need to solve the cache problem from the page itself.
The default cache settings are different for several browsers. You can directly add a disabled cache on the page.
HTML
<META HTTP-EQUIV = "pragma" CONTENT = "no-cache">
<META HTTP-EQUIV = "Cache-Control" CONTENT = "no-cache, must-revalidate">
<META HTTP-EQUIV = "expires" CONTENT = "Mon, 23 Jan 1978 12:52:30 GMT">
ASP
<%
Response. Expires =-1
Response. ExpiresAbsolute = Now ()-1
Response. cachecontrol = "no-cache"
%>
PHP
Header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT ");
Header ("Cache-Control: no-cache, must-revalidate ");
Header ("Pragma: no-cache ");
JSP
Response. setHeader ("Pragma", "No-Cache ");
Response. setHeader ("Cache-Control", "No-Cache ");
Response. setDateHeader ("Expires", 0 );
How to disable cache in C!
Response. Buffer = true;
Response. ExpiresAbsolute = System. DateTime. Now. AddSeconds (-1 );
Response. Expires = 0;
Response. CacheControl = "no-cache ";
Above

Jquery ajax cache Problems

Does the image name remain unchanged? Add a parameter to the image src, as shown in figure
$ ("Img"). attr ("src", "test.jpg? Rand = "+ new Date (). getTime () + Math. random ());

Related 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.