[英]Ajax call is not working in Internet Explorer9 and Internet Explorer10
我使用此功能使用ajax显示项目页面。 它在Chrome上运行良好,但在Internet Explorer中无法正常运行。
<script type="text/javascript">
function grabInfo(str)
{
if (str=="")
{
document.getElementById("contentDiv").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("contentDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","get_property.php?q="+str,true);
xmlhttp.send();
}
</script>
此函数在Chrome上返回更新的结果。但是在Internet Explorer中,此函数返回以前的结果。如果我使用Ctrl + Shift + Del清除会话,系统将显示更新的结果。为什么会这样? 你能帮上忙吗?
提前致谢....
Internet Explorer缓存响应。 您可以使用Math.random()
将随机值添加到请求URL的查询字符串中,也可以在服务器端脚本中包含响应标头。
Cache-Control: no-cache, no-store
问题是IE会缓存请求,只要查询字符串没有变化,它就会返回相同的响应,这可以由服务器端标头处理,
Cache-Control: no-cache, no-store
但是最简单的方法就是像这样修改请求:
xmlhttp.open("GET","get_property.php?q="+str+"&r="+Math.random(),true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.