xmlhttp缓存清除的2种解决方法


方法一:加If-Modified-Since头
xmlhttp多次调用时它却总是显示缓存页面, 尝试在 php 或 asp 中加入相应的http头明确不要缓存, 也没什么效果!!

现在终于找到一个办法啦,就是在 xmlhttp.open 之后发送一个If-Modified-Since头即可, 代码如下
xmlhttp.setRequestHeader('If-Modified-Since', '0');
xmlHttp.onreadystatechange = stateChanged;
            xmlHttp.open("GET", url, true);
            xmlHttp.setRequestHeader('If-Modified-Since', '0');
            xmlHttp.send(null);

方法二:请求URL后加变化参数

因为IE默认将相同的URL请求进行缓存,所以URL加上唯一区分的参数作为区分,保持每次请求的URL不同,即可绕过IE缓存的问题
      js:     URL = "http://host/a.php"+"?"+Math.random();
      vbs:   URL = "http://host/a.php"&"?"&Timer()

 //var url = "ResponseContentPageScore.aspx?key=" + Math.round(Math.random() * 100) + "&HotelCD=" + inputContent;
 var url = "ResponseContentPageScore.aspx?key=" + new Date().getTime() + "&HotelCD=" + inputContent;


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3