2012-07-26 46 views
3

documentation of jQuery AJAX Events所有例子使用的是jQuery的DOM元素的声明绑定这样的:jQuery的结合AJAX事件,而DOM元素

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

我要赶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); 
}); 

但它看起来像它不工作:

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

有没有什么建议?

+0

听起来像是你不”你的页面上没有jQuery。 – Jeff 2012-07-26 15:20:54

+1

@Jeff:TypeError显示的函数是jQuery函数*(obfuscated)*。 jQuery函数也是其他函数和数据的命名空间。该错误是因为该名称空间中没有'ajaxSend'方法。 – 2012-07-26 15:21:49

+0

@amnotiam是的,我注意到了。虽然我没有更好的答案。抱歉。 – Jeff 2012-07-26 15:24:22

回答

4

您可以使用document

$(document).ajaxSend(hander); 
+0

非常好的解决方法,如果存在,我会让问题暂时等待没有_workaround_的解决方案。 – fguillen 2012-07-26 15:46:43

0

听起来像是你想自定义你的Ajax调用中使用$ .fn.ajax电话的伟大工程:

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

Nop,我想绑定所有的AJAX通道来构建一个控制台调试,像这样https://gist.github.com/3182810 – fguillen 2012-07-26 15:45:36