Make sure regular settings object is set as context for all Ajax requests, if none...
[jquery.git] / src / ajax.js
index 07e706c..f1de0f8 100644 (file)
@@ -390,18 +390,19 @@ jQuery.extend({
 
                // Wait for a response to come back
                var onreadystatechange = xhr.onreadystatechange = function( isTimeout ) {
-                       // The request was aborted, clear the interval and decrement jQuery.active
+                       // The request was aborted
                        if ( !xhr || xhr.readyState === 0 ) {
+                               // Opera doesn't call onreadystatechange before this point
+                               // so we simulate the call
+                               if ( !requestDone ) {
+                                       complete();
+                               }
+
                                requestDone = true;
                                if ( xhr ) {
                                        xhr.onreadystatechange = jQuery.noop;
                                }
 
-                               // Handle the global AJAX counter
-                               if ( s.global && ! --jQuery.active ) {
-                                       jQuery.event.trigger( "ajaxStop" );
-                               }
-
                        // The transfer is complete and the data is available, or the request timed out
                        } else if ( !requestDone && xhr && (xhr.readyState === 4 || isTimeout === "timeout") ) {
                                requestDone = true;
@@ -454,13 +455,13 @@ jQuery.extend({
                try {
                        var oldAbort = xhr.abort;
                        xhr.abort = function() {
-                               oldAbort.call( xhr );
                                if ( xhr ) {
-                                       xhr.readyState = 0;
-                               }
-                               if ( !requestDone ) {
-                                       complete();
+                                       oldAbort.call( xhr );
+                                       if ( xhr ) {
+                                               xhr.readyState = 0;
+                                       }
                                }
+
                                onreadystatechange();
                        };
                } catch(e) { }
@@ -477,7 +478,7 @@ jQuery.extend({
 
                // Send the data
                try {
-                       xhr.send( type === "POST" || type === "PUT" ? s.data : null );
+                       xhr.send( type === "POST" || type === "PUT" || type === "DELETE" ? s.data : null );
                } catch(e) {
                        jQuery.handleError(s, xhr, null, e);
                        // Fire the complete handlers
@@ -529,7 +530,7 @@ jQuery.extend({
        handleError: function( s, xhr, status, e ) {
                // If a local callback was specified, fire it
                if ( s.error ) {
-                       s.error.call( s.context || window, xhr, status, e );
+                       s.error.call( s.context || s, xhr, status, e );
                }
 
                // Fire the global callback
@@ -664,7 +665,7 @@ jQuery.extend({
                                                }
                                        });
                                        
-                               } else if ( !traditional && typeof obj === "object" ) {
+                               } else if ( !traditional && obj != null && typeof obj === "object" ) {
                                        // Serialize object item.
                                        jQuery.each( obj, function( k, v ) {
                                                buildParams( prefix + "[" + k + "]", v );