parts,
// The jqXHR state
state = 0,
+ // To know if global events are to be dispatched
+ fireGlobals,
// Loop variable
i,
// Fake xhr
jqXHR.statusCode( statusCode );
statusCode = undefined;
- if ( s.global ) {
+ if ( fireGlobals ) {
globalEventContext.trigger( "ajax" + ( isSuccess ? "Success" : "Error" ),
[ jqXHR, s, isSuccess ? success : error ] );
}
// Complete
completeDeferred.resolveWith( callbackContext, [ jqXHR, statusText ] );
- if ( s.global ) {
+ if ( fireGlobals ) {
globalEventContext.trigger( "ajaxComplete", [ jqXHR, s] );
// Handle the global AJAX counter
if ( !( --jQuery.active ) ) {
// Apply prefilters
inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
+ // If request was aborted inside a prefiler, stop there
+ if ( state === 2 ) {
+ return false;
+ }
+
+ // We can fire global events as of now if asked to
+ fireGlobals = s.global;
+
// Uppercase the type
s.type = s.type.toUpperCase();
s.hasContent = !rnoContent.test( s.type );
// Watch for a new set of requests
- if ( s.global && jQuery.active++ === 0 ) {
+ if ( fireGlobals && jQuery.active++ === 0 ) {
jQuery.event.trigger( "ajaxStart" );
}
// Set state as sending
state = jqXHR.readyState = 1;
// Send global event
- if ( s.global ) {
+ if ( fireGlobals ) {
globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
}
// Timeout
});
+test("jQuery.ajax - abort in prefilter", function() {
+
+ expect( 1 );
+
+ jQuery.ajaxPrefilter(function( options, _, jqXHR ) {
+ if ( options.abortInPrefilter ) {
+ jqXHR.abort();
+ }
+ });
+
+ strictEqual( jQuery.ajax({
+ abortInPrefilter: true,
+ error: function() {
+ ok( false, "error callback called" );
+ }
+ }), false, "Request was properly aborted early by the prefilter" );
+
+});
+
test("jQuery.ajax - active counter", function() {
ok( jQuery.active == 0, "ajax active counter should be zero: " + jQuery.active );
});