Adds jQuery collection to objects that will be used as global events context if provi...
[jquery.git] / src / ajax.js
index 4830e3d..76f9834 100644 (file)
@@ -365,9 +365,10 @@ jQuery.extend({
                                ( s.context = ( "context" in options ? options : jQuery.ajaxSettings ).context ) || s,
                        // Context for global events
                        // It's the callbackContext if one was provided in the options
-                       // and if it's a DOM node
-                       globalEventContext = callbackContext !== s && callbackContext.nodeType ?
-                               jQuery( callbackContext ) : jQuery.event,
+                       // and if it's a DOM node or a jQuery collection
+                       globalEventContext = callbackContext !== s &&
+                               ( callbackContext.nodeType || callbackContext instanceof jQuery ) ?
+                                               jQuery( callbackContext ) : jQuery.event,
                        // Deferreds
                        deferred = jQuery.Deferred(),
                        completeDeferred = jQuery._Deferred(),
@@ -684,8 +685,7 @@ jQuery.extend({
                if ( !transport ) {
                        done( -1, "No Transport" );
                } else {
-                       // Set state as sending
-                       state = jqXHR.readyState = 1;
+                       jqXHR.readyState = 1;
                        // Send global event
                        if ( fireGlobals ) {
                                globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
@@ -698,6 +698,7 @@ jQuery.extend({
                        }
 
                        try {
+                               state = 1;
                                transport.send( requestHeaders, done );
                        } catch (e) {
                                // Propagate exception as error if not done