大家在系統(tǒng)開(kāi)發(fā)中都可能會(huì)在js中用到ajax或者dwr,因?yàn)镮E的緩存,使得我們?cè)谔钊胂嗤闹档臅r(shí)候總是使用IE緩存,為了解決這個(gè)問(wèn)題一般可以用一下方法:
1:在ajax或者dwr提交的url后面加時(shí)間戳。
例如
http_request.onreadystatechange = funcName(函數(shù)名);
http_request.open("GET", url, true);
比如url是test .jsp
那么我們?cè)谒竺婕由?time=new Date();
即url=test.jsp?time=new Date();
2 :在url后面加一個(gè)隨機(jī)數(shù)。
。。。。。。。。。
url=test.jsp?number=Math.random();
------------------------------------------------------------------
Cache緩存問(wèn)題
由于IE的緩存處理機(jī)制問(wèn)題,每次通過(guò)XMLHttpRequest訪問(wèn)動(dòng)態(tài)頁(yè)面返回的總是首次訪問(wèn)的內(nèi)容,解決方法有:
1. 客戶端通過(guò)添加隨機(jī)字符串解決。如:
var url = 'http://www.bothv.com/';
url += '?temp=' + new Date().getTime();
url += '?temp=' + Math.random();
2. 在HTTP headers禁止緩存。如:
HTTP:
<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" />
PHP:
header("Expires: Thu, 01 Jan 1970 00:00:01 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")
JSP:
response.addHeader("Cache-Control", "no-cache");
response.addHeader("Expires", "Thu, 01 Jan 1970 00:00:01 GMT");
3. 在XMLHttpRequest發(fā)送請(qǐng)求之前加上:
XMLHttpRequest.setRequestHeader("If-Modified-Since","0");
XMLHttpRequest.send(null);