jQuery ajaxSend global event inconsistency ( jQuery 1.4.4 )

jQuery ajaxSend global event inconsistency ( jQuery 1.4.4 )

Hi,

In one of my recent projects I am using/observing "ajaxSend" event for some logging purpose, I am listening on the <body> tag for the event using a code like below:

  1. $( document.body ).bind( 'ajaxSend', function log( event, xhr, settings ) {
  2. console.log( settings.url );
  3. } );
The above code is working fine for almost all the cases except few and I am also able to log the XHR calls properly. But I have noticed that in some cases this "event" does not bubble properly ( I mean that it does not bubble up to the document tree ). This happens when I pass a "context" property while invoking "$.ajax()" call like below:
  1. $.ajax( { context: someObj } ); // other properties are omitted for demonstration purpose
I also see the following code where jQuery is calling the "triggerGlobal()" method which uses the "context" property of the specified "settings object" to trigger the global event.
  1. if ( s.global ) {
  2.     jQuery.triggerGlobal( s, "ajaxSend", [xhr, s] );
  3. }

This summarizes two behaviors that you can see from "ajaxSend":
  1. The "ajaxSend" event bubbles up to the DOM tree when no context is provided.
  2. The "ajaxSend" event does not bubble up to the DOM tree when context is provided.

As I couldn't find this behavior documented anywhere, so I am wondering whether this is a bug or this is how it works, any insight would be highly appreciated.

Note: We are using jQuery 1.4.4 ( we're yet to upgrade to 1.5+ because some plugins are not compatible to 1.5 yet ) and I haven't tested it separately with 1.5 to see whether it is correctly working in that version or not.

Thanks,
Arnab














    • Topic Participants

    • arnab