ajaxError and ajaxComplete firing twice upon abort

ajaxError and ajaxComplete firing twice upon abort

I was aborting an ajax request inside ajaxSend function, and I noticed that the ajaxComplete and ajaxError global event handlers bound to document are being called twice, and in their second execution they throw  TypeError: Cannot read property 'send' of undefined.

When aborting ajax calls outside of  ajaxSend, it behaves normally.

Is it supposed to work like this?

Tested using 1.9.1, 1.11.1, 2.1.1


  1. $(document).ajaxSend(function( e, jqXHR ) {
  2.     $("body").append('aborting ajax...<br>');
  3.     jqXHR.abort();
  4. });

  5. $(document).ajaxError(function( e, jqXHR, opts, err ) {
  6.     $("body").append('global ajax Error callback (status: '+ err +')<br>')
  7. });

  8. $(document).ajaxComplete(function( e, jqXHR ) {
  9.     $("body").append('global ajax Complete callback (statusText: '+ jqXHR.statusText +')<br>');
  10. });

  11. $.ajax({
  12.     url: '',
  13.     error: function() {
  14.         $("body").append('specific ajax Error callback<br>');
  15.     },
  16.     complete: function() {
  17.         $("body").append('specific ajax complete callback<br>');
  18.     }
  19. });
  20.