Bug Tracker

Changeset 2770

Show
Ignore:
Timestamp:
08/19/07 00:48:53 (1 year ago)
Author:
jeresig
Message:

We were catching exceptions within the success callback of an Ajax request, then causing an error callback to be called (which is incorrect). (Bug #1441)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/jquery/src/ajax/ajax.js

    r2531 r2770  
    632632                } 
    633633                 
    634                 var status; 
    635                 try { 
    636                     status = isTimeout == "timeout" && "timeout" || 
    637                         !jQuery.httpSuccess( xml ) && "error" || 
    638                         s.ifModified && jQuery.httpNotModified( xml, s.url ) && "notmodified" || 
    639                         "success"; 
    640  
    641                     // Make sure that the request was successful or notmodified 
    642                     if ( status != "error" && status != "timeout" ) { 
    643                         // Cache Last-Modified header, if ifModified mode. 
    644                         var modRes; 
    645                         try { 
    646                             modRes = xml.getResponseHeader("Last-Modified"); 
    647                         } catch(e) {} // swallow exception thrown by FF if header is not available 
    648      
    649                         if ( s.ifModified && modRes ) 
    650                             jQuery.lastModified[s.url] = modRes; 
    651      
     634                var status = isTimeout == "timeout" && "timeout" || 
     635                    !jQuery.httpSuccess( xml ) && "error" || 
     636                    s.ifModified && jQuery.httpNotModified( xml, s.url ) && "notmodified" || 
     637                    "success"; 
     638 
     639                if ( status == "success" ) { 
     640                    // Watch for, and catch, XML document parse errors 
     641                    try { 
    652642                        // process the data (runs the xml through httpData regardless of callback) 
    653643                        var data = jQuery.httpData( xml, s.dataType ); 
     644                    } catch(e) { 
     645                        status = "parsererror"; 
     646                    } 
     647                } 
     648 
     649                // Make sure that the request was successful or notmodified 
     650                if ( status == "success" ) { 
     651                    // Cache Last-Modified header, if ifModified mode. 
     652                    var modRes; 
     653                    try { 
     654                        modRes = xml.getResponseHeader("Last-Modified"); 
     655                    } catch(e) {} // swallow exception thrown by FF if header is not available 
    654656     
    655                         // If a local callback was specified, fire it and pass it the data 
    656                         if ( s.success ) 
    657                             s.success( data, status ); 
     657                    if ( s.ifModified && modRes ) 
     658                        jQuery.lastModified[s.url] = modRes; 
    658659     
    659                         // Fire the global callback 
    660                         if( s.global ) 
    661                             jQuery.event.trigger( "ajaxSuccess", [xml, s] ); 
    662                     } else 
    663                         jQuery.handleError(s, xml, status); 
    664                 } catch(e) { 
    665                     status = "parsererror"; 
    666                     jQuery.handleError(s, xml, status, e); 
    667                 } 
     660                    // If a local callback was specified, fire it and pass it the data 
     661                    if ( s.success ) 
     662                        s.success( data, status ); 
     663     
     664                    // Fire the global callback 
     665                    if( s.global ) 
     666                        jQuery.event.trigger( "ajaxSuccess", [xml, s] ); 
     667                } else 
     668                    jQuery.handleError(s, xml, status); 
    668669 
    669670                // The request was completed