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
- $(document).ajaxSend(function( e, jqXHR ) {
- $("body").append('aborting ajax...<br>');
- jqXHR.abort();
- });
- $(document).ajaxError(function( e, jqXHR, opts, err ) {
- $("body").append('global ajax Error callback (status: '+ err +')<br>')
- });
- $(document).ajaxComplete(function( e, jqXHR ) {
- $("body").append('global ajax Complete callback (statusText: '+ jqXHR.statusText +')<br>');
- });
- $.ajax({
- url: '',
- error: function() {
- $("body").append('specific ajax Error callback<br>');
- },
- complete: function() {
- $("body").append('specific ajax complete callback<br>');
- }
- });
-