简体   繁体   English

jQuery绑定没有DOM元素的AJAX事件

[英]jQuery binding AJAX events without DOM element

In the documentation of jQuery AJAX Events all the examples use a jQuery DOM Element for declare a binding like this: jQuery AJAX Events文档中,所有示例都使用jQuery DOM Element来声明这样的绑定:

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

I want to catch jQuery AJAX Events without the need of having a DOM Element to attach them, like this: 我想捕获jQuery AJAX事件而不需要使用DOM元素来附加它们,如下所示:

$.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? 有什么建议吗?

你可以使用这个document

$(document).ajaxSend( hander );

听起来你想要自定义你的ajax调用,其中使用$ .fn.ajax调用很有效:

$.ajax('{your_url}', options);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM