Bug Tracker

Opened 10 years ago

Closed 10 years ago

Last modified 8 years ago

#6748 closed bug (duplicate)

xhr.status === 0 should be treated as 304 (Not Modified) only in Opera

Reported by: benjamn Owned by:
Priority: undecided Milestone: 1.4.3
Component: ajax Version: 1.4.2
Keywords: Cc:
Blocked by: Blocking:

Description

Consider the boolean expression returned by httpSuccess():

    return !xhr.status && location.protocol === "file:" ||
        // Opera returns 0 when status is 304
        ( xhr.status >= 200 && xhr.status < 300 ) ||
        xhr.status === 304 || xhr.status === 1223 || xhr.status === 0;

Opera may indeed return 0 when the status should be 304, but other browsers (notably, Chrome Mac) return 0 as a result of certain errors (e.g., same-origin restrictions).

Treating xhr.status === 0 as success is a special case that should apply only in Opera. This subtle difference in behavior could be keeping folks from upgrading from 1.3.x, so it should be fixed if possible.

Attachments (1)

0001-Treat-an-xhr.status-of-0-as-successful-only-in-Opera.patch (1.3 KB) - added by benjamn 10 years ago.
Patch to make the Opera special case more Opera-specific.

Download all attachments as: .zip

Change History (10)

Changed 10 years ago by benjamn

Patch to make the Opera special case more Opera-specific.

comment:1 Changed 10 years ago by dmethvin

Hi, do you have any further information on this bug? We try hard to avoid use of jQuery.browser. Is there any doc or acknowledgment by Opera about it that you can find?

comment:2 in reply to:  1 ; Changed 10 years ago by benjamn

Replying to dmethvin:

Hi, do you have any further information on this bug? We try hard to avoid use of jQuery.browser. Is there any doc or acknowledgment by Opera about it that you can find?

The original code contains an explicit special case for Opera, as indicated by the existing comment. Treating xhr.status === 0 as success in any browser other than Opera is incorrect. I would be happy for jQuery to drop support for this Opera quirk by removing the xhr.status === 0 clause altogether, but if we're trying to pander to a single browser's bug, then we should at least be precise about it. If there is any acceptable use of jQuery.browser.opera, this is such a case.

comment:4 in reply to:  2 ; Changed 10 years ago by execjosh

Replying to benjamn:

Replying to dmethvin:

Hi, do you have any further information on this bug? We try hard to avoid use of jQuery.browser. Is there any doc or acknowledgment by Opera about it that you can find?

The original code contains an explicit special case for Opera, as indicated by the existing comment. Treating xhr.status === 0 as success in any browser other than Opera is incorrect. I would be happy for jQuery to drop support for this Opera quirk by removing the xhr.status === 0 clause altogether, but if we're trying to pander to a single browser's bug, then we should at least be precise about it. If there is any acceptable use of jQuery.browser.opera, this is such a case.

I agree that there is a need to be precise in code and not only in comments.

In my tests, I have found that this issue affects at least:

  • Chrome (v5.0.375.99)
  • Firefox (v3.6.6)

Test Code

Setup

  1. Make code accessible via http from server
  2. Load html file in browser on client
    1. Ensure client and server are different machines
    2. Ensure direct connection (i.e., _no proxy_) between client and server
    3. I used VirtualBox locally, connected via host-only network
  3. Sever connection betweent client and server
  4. Press button and wait for result

Expected Results

OnError["504", "error", ""]

Actual Results

OnSuccess["0", "success", ""]

Code

filename: jquery-bug-6748.html

<!DOCTYPE html>
<title>jQuery bug #6748</title>
<script src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<input id="b" type="button" value="jQuery-bug-6748">
<div id="p"></div>
<script>
(function($){
  $(document).ready(function(){
    function f(n,x,s,e){$('#p').html(['<div>',n,'["',x.status,'", "',s,'", "',e,'"]</div>'].join(""))}
    $('#b').click(function(){
      $.ajax({
        async:true,
        cache:false,
        error:function(x,s,e){f('OnError',x,s,e)},
        success:function(d,s,x){f('OnSuccess',x,s)}
      });
    });
  });
})(jQuery);
</script>

comment:5 in reply to:  4 Changed 10 years ago by execjosh

Expected Results OnError["504", "error", ""]

Woops, this was generated using a proxy...
It should read as follows OnError["0","error",""].

comment:6 Changed 10 years ago by curiousdannii

Duplicate of #6060

comment:7 Changed 10 years ago by curiousdannii

Please close as #6060 has been fixed.

comment:8 Changed 10 years ago by dmethvin

Priority: undecided
Resolution: duplicate
Status: newclosed

comment:9 Changed 10 years ago by Rick Waldron

#7647 is a duplicate of this ticket.

Note: See TracTickets for help on using tickets.