简体   繁体   English

Google Chrome 28.0.1500.72及更高版本中的Ajax打开功能问题

[英]Issue with Ajax open function in google chrome 28.0.1500.72 and later

I think I found an issue where ajax open functions are not behaving properly in google chrome after the version 28.0.1500.72 update. 我想我发现了一个问题,在28.0.1500.72版本更新后,ajax打开功能在Google Chrome中无法正常运行。 This issue was originally found using an embedded webserver as the server, but I have been able to reproduce it on an apache webserver as well. 最初使用嵌入式Web服务器作为服务器时发现了此问题,但是我也能够在apache Web服务器上重现它。

The issue occurs when I call ajaxObject.open("GET","URL",true). 当我调用ajaxObject.open(“ GET”,“ URL”,true)时,会发生此问题。 This usually works, however sometimes the client pc running the javascript will not issue a GET request for the url(This has been confirmed using wireshark). 这通常是可行的,但是有时运行javascript的客户端PC不会发出url的GET请求(已使用Wireshark进行了确认)。 At this point ajaxObject.readyState changes from 1 to 2 to 4 as if it sent the request properly and received a response. 此时,ajaxObject.readyState从1变为2到4,就好像它正确发送了请求并收到了响应。 This issue did not occur with chrome previously, and is not an issue on IE or firefox. chrome以前没有发生此问题,而IE或firefox上没有此问题。 Interestingly, on a successful call, ajaxObject.readyState goes from 1, to 2, to 3, to 4. 有趣的是,在成功调用后,ajaxObject.readyState从1变为2,再从3变为4。

We've hard coded the headers on our embedded webserver to not cache the requested page fetched via ajax, as we need to request the page over and over again and refresh it's contents. 我们已经对嵌入式Web服务器上的标头进行了硬编码,以不缓存通过ajax提取的请求页面,因为我们需要反复请求该页面并刷新其内容。 To duplicate this functionality on apache, I added: 为了在apache上复制此功能,我添加了:

<FilesMatch ".(shtml|html|js|css)$"> 
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
</FilesMatch>

to the httdp-conf file. 到httdp-conf文件。

The following is the html page that I am able to reproduce the issue on. 以下是我能够在其上重现该问题的html页面。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>

<script type="text/javascript">
function newAjaxObject() {
    var xmlHttp;
    try {           // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    } catch (e) {   // Internet Explorer
        try {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                alert("Your browser does not support Javascript/AJAX!  Please upgrade your browser.");
                return null;
            }
        }
    }
    return xmlHttp;
}

function getStatus() {
    var ajaxStatus = newAjaxObject();

    ajaxStatus.onreadystatechange=function() {
        if(ajaxStatus.readyState==4) {
          eval('var tester =' + ajaxStatus.responseText);
          queueStatusUpdate();  
        }
    }
    ajaxStatus.open("GET","status.shtml",true);
    ajaxStatus.send(null);
}

// Wait 'timeDelay' milliseconds before requesting an update
var timeDelay = 100;
function queueStatusUpdate() {
    setTimeout('getStatus()',timeDelay);
}
</script>
</head>

<body onload="queueStatusUpdate();">

</body>
</html>

This is the response text that should be in the status.shtml page: 这是应该在status.shtml页面中的响应文本:

{"status":"Valid Data"}

工作断点工作要求

Using the network tab in the chrome debugger, navigate to the page and hit refresh until you see that it stops requesting status.shtml and an error has been thrown. 使用chrome调试器中的网络标签,导航至该页面并点击刷新,直到看到它停止请求status.shtml并引发错误为止。

没有发送请求状态为0的断点

I believe this is an issue with Chrome, but thought I'd post it here before submitting it as a bug for them just in case I am missing something simple. 我认为这是Chrome的问题,但是我想在将其提交给他们之前将其发布给他们,以防他们错过一些简单的事情。

Also, changing from an asynchronous request to a synchronous request fixes the issue, but that is not the route I want to take. 同样,从异步请求更改为同步请求也可以解决此问题,但这不是我要采用的路由。

Thanks ! 谢谢 !

I ran into the same Chrome bug and I was able to confirm it with your code. 我遇到了同一个Chrome错误,并能够通过您的代码进行确认。 The workaround I found was to append a random parameter to the URL (something like ?rand=XYZ, to make the URL unique) and just re-try the original AJAX request with the new URL. 我发现的解决方法是在URL上附加一个随机参数(类似于?rand = XYZ,以使URL唯一),然后使用新URL重试原始AJAX请求。

Based on my testing, here is some information that might be helpful: 根据我的测试,以下一些信息可能会有所帮助:

  • I was able to reproduce the bug on the latest stable version of Chrome: 28.0.1500.95 我能够在最新的稳定版Chrome:28.0.1500.95上重现该错误。

  • I was only able to reproduce the bug on the Windows version. 我只能在Windows版本上重现该错误。 I also tested the same version of Chrome on OSX and I was unable to reproduce it there. 我还在OSX上测试了相同版本的Chrome,但无法在此处复制它。

  • The bug appears when an AJAX request is interrupted by leaving the page and then persists for the entire life of that tab (this is why it's important to refresh the test page until the bug shows up). 当AJAX请求被离开页面而中断并在该选项卡的整个生命周期中持续存在时,该bug就会出现(这就是刷新测试页面直到该bug出现很重要的原因)。 Once a request fails, all future requests for that resource in the same tab will fail, even if the page is reloaded. 一旦请求失败,即使重新加载页面,将来在同一选项卡中对该资源的所有将来请求也将失败。

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

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