简体   繁体   English

Google Chrome无法在连接关闭时加载XMLHttpRequest响应

[英]Google Chrome fails to load XMLHttpRequest response on Connection close

I'm implementing a "load more" functionality, using XMLHttpRequest (AJAX). 我正在使用XMLHttpRequest(AJAX)实现“更多加载”功能。 The webserver will respond to those calls with a Keep-Alive: timeout=5,max=10 and a Connection: keep-alive headers. 网络服务器将使用Keep-Alive:timeout = 5,max = 10和Connection:keep-alive标头响应这些调用。 On the 10 response it sends a Connection: close header, as expected. 在10响应上,它按预期发送Connection:close标头。 All browsers (Safari, Opera, Firefox) continue to process the response, except Chrome. 除Chrome之外,所有浏览器(Safari,Opera,Firefox)都将继续处理响应。 It stops with a status code 0 and no response text. 它以状态代码0停止并且没有响应文本。

Here is the JavaScript snippet: 这是JavaScript代码段:

function send(method, data) {
    try {
        let this._request = null;
        let created = false;
        if (!(this._request instanceof XMLHttpRequest)) {
            this._request = new XMLHttpRequest();
            this._request.onreadystatechange = (event) => {
                switch (this._request.readyState) {
                    case XMLHttpRequest.OPENED: {
                        // Do something
                    } break;
                    case XMLHttpRequest.LOADING: {
                        // Do something
                    } break;
                    case XMLHttpRequest.DONE: {
                        // Do something
                    } break;
                }
            };
            this._request.addEventListener(
                'error',
                (event) => {
                        // Do something
                }
            );
            this._request.addEventListener(
                'abort',
                (event) => {
                        // Do something
                }
            );
            created = true;
        }
        this._request.open(String(method), this.path);
        this._request.timeout = 200;
        if (created) {
            // Initialization is done here, like setting request headers...
        }
        this._request.send(data);
    } catch (error) {}
}

Any ideas why Chrome is behaving that way? 关于Chrome为何采用这种方式的任何想法?

事实证明,在Chrome中,超时是渐进的,这意味着不会为每个请求重置超时。

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

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