// 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;
try {
var oldAbort = xhr.abort;
xhr.abort = function() {
- oldAbort.call( xhr );
-
- if ( !requestDone ) {
- complete();
- }
-
if ( xhr ) {
- xhr.onreadystatechange = null;
+ oldAbort.call( xhr );
+ if ( xhr ) {
+ xhr.readyState = 0;
+ }
}
- requestDone = true;
+ onreadystatechange();
};
} catch(e) { }
// 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
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
}
});
- } 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 );