解决IE浏览器中解决IE浏览中AJAX只能运一次的IE缓存问题
来源:互联网 发布:晚会抽奖软件 编辑:程序博客网 时间:2024/05/16 12:34
大家在系统开发中都可能会在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();
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的缓存处理机制问题,每次通过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);
0 0
- 解决IE浏览器中解决IE浏览中AJAX只能运一次的IE缓存问题
- 解决IE浏览器中解决IE浏览中AJAX只能运一次的IE缓存问题
- 解决Ajax在IE浏览器中缓存问题
- 解决ajax调用中ie的缓存问题
- Ajax中IE浏览器中的缓存问题
- IE浏览器中ajax使用缓存数据的问题
- 解决ie缓存的问题
- 重写jquery的ajax,解决ie缓存
- Ajax解决IE浏览器兼容问题
- 解决IE下AJAX缓存问题的三种方法
- IE浏览器中对图片点击“右键另存为”只能是bmp格式的解决
- IE中ajax+jsp登录界面,由于缓存导致jsp过滤器与ajax请求被拦截的问题和解决
- IE中ajax+jsp登录界面,由于缓存导致jsp过滤器与ajax请求被拦截的问题和解决
- 解决IE下jquery ajax无法获得最新数据的问题(IE缓存)
- 解决IE无法浏览
- 兼容解决 IE 、火狐、谷歌浏览器中 Iframe框架的页面缓存的方法
- 兼容解决 IE 、火狐、谷歌浏览器中 Iframe框架的页面缓存的方法
- 解决IE浏览器无法重装的问题
- 线性表的基本操作及应用
- 在aspx网页中使用program控件
- 交流
- 让多个fragment切换时不被实例化 android
- 使用DML语句更改数据
- 解决IE浏览器中解决IE浏览中AJAX只能运一次的IE缓存问题
- Android 的生命周期知识点问答
- 百度云推送折腾笔记
- 20160108 CodeBlocks与正则表达式
- Android SearchView设置与用法的那点事儿
- 【慕课笔记】第二章 变量和常量 第5节 JAVA中的数据类型
- iOS开发 UI 设计模式
- Web Service 的工作原理
- ROS naviagtion analysis: costmap_2d--Costmap2DROS