javascript - 我使用 javascript 和 ajax 创建了一个在线打字测试页面。该代码在 google chrome firefox 中运行良好,但在 Internet Explorer 中运行不佳

标签 javascript ajax internet-explorer

在 Internet Explorer 中,当我刷新单词时,会再次收到相同的响应。 这是在 onclick 事件上刷​​新单词列表的函数。

function refresh() {

            // divs in which words to be set


            var xmlhttp;
                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) {

                /*

                ------------

                -----------
                logic in which words are received from database in a para and then separated and inserted in 
                div where words are to be displayed.

                -----------
                -----------

                */


                } 
            xmlhttp.open("GET","getdata.php",true);
            xmlhttp.send();

            }// refresh

getdata.php中,从数据库中随机选择一个段落,然后在上面的if block 中分隔单词。整个代码在所有浏览器中都能正常工作(即收到随机段落),但在 Internet Explorer 中,第一次加载的同一段落会一次又一次地收到。

我完全困惑为什么它在 IE 中不起作用。如果有人有想法,请告诉我为什么会发生这种情况以及需要进行哪些修改。

有关该问题的更多说明,请查看此链接 http://www.geekzgarage.com/typing-test/在 Chrome 中,然后单击刷新图像。您每次都会看到随机单词。但在 IE 中,每次刷新后都会出现相同的单词。注意:这个问题可能已经在上面提到的链接上得到解决。

最佳答案

可能是对 getdata.php 的请求被浏览器缓存了。 尝试在 URL 末尾添加时间戳。

关于javascript - 我使用 javascript 和 ajax 创建了一个在线打字测试页面。该代码在 google chrome firefox 中运行良好,但在 Internet Explorer 中运行不佳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28661449/

相关文章:

javascript - 使用 jquery 检测变量变化

javascript - 与 jQuery ajax post 方法相比,fetch 方法未按预期发布

javascript - 根据另一个选择下拉列表中选择的年份动态显示选择下拉列表中剩余的可用月份

python - 在 Django 提供的 IFrame 中显示 PDF 时,IE 8 崩溃

javascript - 无限滚动+ masonry 崩溃

javascript - 如果 mData 为 null,jQuery DataTable : Callback function(fnUpdate, fnCreatedCell 等)将不起作用

javascript - 背景颜色变化的瓷砖

javascript - 一劳永逸 : Is there or is there not a way to manipulate an image from another domain using IE9+

html - 如何在跨度中包装文本?

javascript - 如果有人已经在里面,ReactJs 会阻止某人加载页面