解决IE浏览器中AJAX只能运行一次的IE缓存问题

大家在系统开发中都可能会在js中用到ajax或者dwr,因为IE的缓存,使得我们在填入相同的值的时候总是使用IE缓存,为了解决这个问题一般可以用一下方法:
       1:在ajax或者dwr提交的url后面加时间戳。
       例如
    http_request.onreadystatechange = funcName(函数名);
   http_request.open("GET", url, true);
    比如url是test .jsp
    那么我们在它后面加上?time=new Date();
即url=test.jsp?time=new Date();
       2 :在url后面加一个随机数。
     。。。。。。。。。
     url=test.jsp?number=Math.random();
------------------------------------------------------------------
Cache缓存问题

由于IE的缓存处理机制问题,每次通过XMLHttpRequest访问动态页面返回的总是首次访问的内容,解决方法有:

   1. 客户端通过添加随机字符串解决。如:
      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发送请求之前加上:
      XMLHttpRequest.setRequestHeader("If-Modified-Since","0");
      XMLHttpRequest.send(null);

转载于:https://www.cnblogs.com/kingangWang/archive/2011/10/13/2210488.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值