3

In the documentation of jQuery AJAX Events all the examples use a jQuery DOM Element for declare a binding like this:

$('.log').ajaxSend( hander );

I want to catch jQuery AJAX Events without the need of having a DOM Element to attach them, like this:

$.ajaxSend( function( event, jqXHR, ajaxOptions ){
  console.log( "ajaxSend" );
  console.log( "ajaxSend.event", event );
  console.log( "ajaxSend.jqXHR", jqXHR );
  console.log( "ajaxSend.ajaxOptions", ajaxOptions );
});

But It looks like it doesn't work:

Uncaught TypeError: Object function (a,b){return new e.fn.init(a,b,h)} has no method 'ajaxSend' 

Any suggestion?

4

2 回答 2

4

你可以使用document

$(document).ajaxSend( hander );
于 2012-07-26T15:11:09.923 回答
0

听起来您想自定义 ajax 调用,其中使用 $.fn.ajax 调用效果很好:

$.ajax('{your_url}', options);
于 2012-07-26T15:40:30.337 回答