I want to set up global behavior for all AJAX requests,
and sometimes I need to interrupt queue
like this
$.ajaxSetup({
success: function(data, textStatus, jqXHR) {
if ( data.error ) { jqXHR.reject(); }
}
});
// later
$.ajax({ some: option }).done( function(html) { do_something(html); } );
here I want to finish (do not call done with function(html))
when data.error is present
Is it possible ?
Or maybe exists another way for it ?
You can’t resolve the jqXHR directly.
The jqXHR implements the Promise interface, which can be used to get the state or add callbacks but, can’t be used to change the state.
Reference http://api.jquery.com/jQuery.ajax/#jqXHR
Did you try $.ajaxSetup(success: defaultHandler})? But this will work only if you provide a handler in the original options. like : $.ajax({url: ‘someurl’ , success: someHandler});
For more ideas , see if this helps:
http://forum.jquery.com/topic/stop-a-deferred-callback-queue-in-progress