页面有缓存的话,发送的get请求若和缓存中数据请求一致,浏览器会默认不去服务器请求,而是从缓存中取得数据,浏览器设计初衷是为了加速页面显示,但是,有时,确实需要请求服务器新的数据,这样就有问题了。
有以下几种方法解决
1、在地址后面加上 随机数,或时间
导致每次请求的地址都发生变化,从而有效的防止了ie缓存,比较常见的应用有, 验证码图片地址的生成。
如 URL+"&"
+
"t="
+Math.random();
new Date().getTime();
2、html:
<META HTTP-EQUIV="pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">
<META HTTP-EQUIV="expires" CONTENT="0">
JSP 或action:
response.addHeader("Cache-Control", "no-cache");
response.addHeader("Expires", "Thu, 01 Jan 1970 00:00:01 GMT");
PHP:
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
ASP:
response.expires=0
response.addHeader("pragma","no-cache")
response.addHeader("Cache-Control","no-cache, must-revalidate")