简体   繁体   中英

Chrome downloads the reloaded page on HTTP 205 response after an AJAX request

Working on a project, I just make an AJAX request to process some datas.
The server, once the job is done, returns a HTTP 205 RESET CONTENT response

I use this status code to tell the requester to reset the document view

Here is the piece of code I use

$.ajax({
    url: '/unread',
    method: 'PUT',
    data: {
        notifications: elements
    }
}).done(function(content, message, xhr) {
    if (205 !== xhr.status) {
        // Generic error message
        return;
    }

    window.location.reload(true)
}).fail(function() {
    // Generic error message
})

This works fine on Internet Explorer (8 and upwards) , Firefox (28.0) and Opera (12.16) . However Chrome (33.0) and Opera (20.0) instead of refreshing the page, downloads the response content of the page being reloaded dump when calling window.location.reload

Here's what I've tried

  • window.location.href = window.location.href gives the same result
  • history.go(0) gives the same result
  • If I remove the window.location.reload , nothing gets reloaded
  • Clearing the cache, removing the local state or going in private navigation doesn't change anything
  • If I change the response code (eg 204), it works fine

Here is the visual network of what's happening

Chrome即可下载

Additionnal informations (and deeper investigations)

  • I'm on Ubuntu 12.04
  • Error could be reproduced on a different computer with Windows 7 (Same chrome version)
  • Error couldn't be reproduced on a different computer with Debian 7.1 (Same chrome version)

Why does Chrome and Opera behave like this on a 205 HTTP response?

The closest I could find was that it might be a bug, because in this file: https://chromium.googlesource.com/chromium/chromium/+/trunk/net/http/http_stream_parser.cc

the comment starting at line 837 does not match the code at line 850: ie the comment doesn't mention that a 205 must be of zero length, but the code treats 205 like 1xx, 204, and 304. That was actually the only blink code I could find that mentioned 205 (outside of defining constants).

It might also be worth trying the latest Opera version; if the problem also happens there, it points the finger more strongly at a bug in the Blink source code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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