前几天本人在写一个AJAX页面,发现页面没有刷新,还以为是AJAX没工作,一跟踪,原来是每次读到的都是旧数据,也就是本地缓存的数据.
A few days ago, when I writing a AJAX page to refresh content, but I find nothing changed. then I use Fiddler to hack in. Yes, AJAX is working, but read from local cache, not remote server.
怎样强迫IE每次都读取新的页面?
How to force IE read from remote server every time?
方法一:在AJAX代码中加上
xmlhttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2005 00:00:00 GMT");
这样自然每次都会读取.
Method 1: In your AJAX code, add something like this:
xmlhttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2005 00:00:00 GMT");
方法二:IE缓存是通过URL对比的,只要换个新的URL就可以更新了.比如加上Time Stamp.
Method2: IE check its cache by URL, so just use another URL, like add a timestamp;
var url = "sum.phtml?figure1=5&figure2=1×tamp=" + new Date().getTime();
方法三:在服务器端修改Header:
ASP.NET :
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
实际上就是修改Header.
Method3:
If you own the remote server, you can change the page's Header.
In Asp.net, code like this:
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);

没有评论:
发表评论