Bug Tracker

Ticket #6060: 0001-Fix-jQuery.ajax-success-function-being-called-when-H.patch

File 0001-Fix-jQuery.ajax-success-function-being-called-when-H.patch, 1.8 KB (added by nic_bellamy, 10 years ago)

Fix jQuery.ajax() success function being called when HTTP connection refused.

  • jquery-1.4.2.js

    From 7ff74dd81ccfa76d65001d4120b32ba9f2d2446f Mon Sep 17 00:00:00 2001
    From: Nic Bellamy <REDACTED>
    Date: Wed, 9 Jun 2010 13:06:38 +1200
    Subject: [PATCH] Fix jQuery.ajax() success function being called when HTTP connection refused.
    
    Fix a bug introduced in commit c3c94823f27ee1e935586d46fd86f055f3a3d97d whereby
    an AJAX request that was refused by the server at the TCP level (ie. connection
    refused) would call the success function with null data.
    
    Opera returns 0 when HTTP status is 304 _or_ when the connection to the server
    is refused. Other browsers return 0 when the connection to the server is
    refused, and return 304 status correctly.
    ---
     jquery-1.4.2.js |   13 +++++++++++--
     1 files changed, 11 insertions(+), 2 deletions(-)
    
    diff --git a/jquery-1.4.2.js b/jquery-1.4.2.js
    index fff6776..3cf7f59 100644
    a b jQuery.extend({ 
    53205320                        return !xhr.status && location.protocol === "file:" ||
    53215321                                // Opera returns 0 when status is 304
    53225322                                ( xhr.status >= 200 && xhr.status < 300 ) ||
    5323                                 xhr.status === 304 || xhr.status === 1223 || xhr.status === 0;
     5323                                xhr.status === 304 || xhr.status === 1223 ||
     5324                                // Opera returns 0 when HTTP status is 304 _or_
     5325                                // when the connection to the server is
     5326                                // refused. Other browsers return 0 when the
     5327                                // connection to the server is refused, and
     5328                                // return 304 status correctly.
     5329                                (jQuery.browser.opera && xhr.status === 0);
    53245330                } catch(e) {}
    53255331
    53265332                return false;
    jQuery.extend({ 
    53405346                }
    53415347
    53425348                // Opera returns 0 when status is 304
    5343                 return xhr.status === 304 || xhr.status === 0;
     5349                return xhr.status === 304 ||
     5350                        // Opera returns 0 when HTTP status is 304 _or_ when
     5351                        // the connection to the server is refused.
     5352                        (jQuery.browser.opera && xhr.status === 0);
    53445353        },
    53455354
    53465355        httpData: function( xhr, type, s ) {