解决IE浏览器中解决IE浏览中AJAX只能运一次的IE缓存问题
2017-08-29 11:23
316 查看
转载:http://blog.csdn.net/q1054261752/article/details/50485408
大家在系统开发中都可能会在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);
大家在系统开发中都可能会在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);
相关文章推荐
- 解决IE浏览器中解决IE浏览中AJAX只能运一次的IE缓存问题
- 解决IE浏览器中AJAX只能运行一次的IE缓存问题
- jquery 请求ie缓存,数据不更新的问题【ajax禁用缓存解决ie数据不更新的问题】
- jquery 请求ie缓存,数据不更新的问题【ajax禁用缓存解决ie数据不更新的问题】
- jquery 请求ie缓存,数据不更新的问题【ajax禁用缓存解决ie数据不更新的问题】
- IE8浏览器缓存问题导致Ajax的GET请求只能执行一次的解决办法
- jquery 请求ie缓存,数据不更新的问题【ajax禁用缓存解决ie数据不更新的问题】
- jquery 请求ie缓存,数据不更新的问题【ajax禁用缓存解决ie数据不更新的问题】
- jquery 请求ie缓存,数据不更新的问题【ajax禁用缓存解决ie数据不更新的问题】
- jquery 请求ie缓存,数据不更新的问题【ajax禁用缓存解决ie数据不更新的问题】
- 解决ie下ajaxsubmit上传文件提示下载文件问题
- jquery 的$.ajax()方法在ie8中只能访问一次后台问题。
- SpringMVC+ajaxFileUpload上传图片 IE浏览器弹下载框问题解决方案
- IE浏览器中的ajax缓存问题与new Date()兼容性问题的解决方法
- 关于解决JQuery发送Ajax请求后,IE缓存数据不更新的问题
- 解决ajax调用中ie的缓存问题
- 解决ajaxfileupload插件在IE10以下不兼容的问题
- 您一次只能安装一种 Adobe 产品问题的解决
- JavaScript-RegExp对象只能使用一次问题解决方法
- dataTables本地刷新数据解决只能初始化一次问题