Home Google Chrome fails to load XMLHttpRequest response on Connection close
Reply: 0

Google Chrome fails to load XMLHttpRequest response on Connection close

user1894
1#
user1894 Published in April 22, 2018, 4:55 am

I'm implementing a "load more" functionality, using XMLHttpRequest (AJAX). The webserver will respond to those calls with a Keep-Alive: timeout=5,max=10 and a Connection: keep-alive headers. On the 10 response it sends a Connection: close header, as expected. All browsers (Safari, Opera, Firefox) continue to process the response, except Chrome. It stops with a status code 0 and no response text.

Here is the JavaScript snippet:

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?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.311424 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO