简体   繁体   English

Ajax呼叫在Internet Explorer9和Internet Explorer10中不起作用

[英]Ajax call is not working in Internet Explorer9 and Internet Explorer10

i used this function to display item page using ajax. 我使用此功能使用ajax显示项目页面。 it is working fine on Chrome.but not in internet explorer. 它在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>

This function is returning the updated results on Chrome.But in Internet Explorer, this function returns the previous results.If i clear sessions using Ctrl+Shift+Del, system shows updated results.why is this happening? 此函数在Chrome上返回更新的结果。但是在Internet Explorer中,此函数返回以前的结果。如果我使用Ctrl + Shift + Del清除会话,系统将显示更新的结果。为什么会这样? Can you help on this? 你能帮上忙吗?

Thanks in Advance.... 提前致谢....

Internet Explorer caches responses. Internet Explorer缓存响应。 You can either add a random value to the request URL's query string using Math.random() or include a response header in the server-side script. 您可以使用Math.random()将随机值添加到请求URL的查询字符串中,也可以在服务器端脚本中包含响应标头。

Cache-Control: no-cache, no-store

The issue is that IE caches the request, as long as query string doesn't change it returns the same response, this can be handled by server side headers, 问题是IE会缓存请求,只要查询字符串没有变化,它就会返回相同的响应,这可以由服务器端标头处理,

Cache-Control: no-cache, no-store

but the easiest way is just to modify the request like this: 但是最简单的方法就是像这样修改请求:

xmlhttp.open("GET","get_property.php?q="+str+"&r="+Math.random(),true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM