Jquery ajaxStart和ajaxComplete是否可以使用.live()?

Jquery ajaxStart和ajaxComplete是否可以使用.live()?,jquery,Jquery,我使用jQuery1.4.4,想知道是否可以将.live()用于ajaxStart/ajaxComplete等Ajax事件。我已经用.bind()绑定了这些事件,它一直有效到现在 jQuery(sourceId).bind("ajaxSend", function(event, xhr, ajaxOptions) { // do something }); equivalent jQuery(sourceId).ajaxSend(function(event, xhr, ajaxOp

我使用jQuery1.4.4,想知道是否可以将.live()用于ajaxStart/ajaxComplete等Ajax事件。我已经用.bind()绑定了这些事件,它一直有效到现在

jQuery(sourceId).bind("ajaxSend", function(event, xhr, ajaxOptions) {
    // do something
});

equivalent

jQuery(sourceId).ajaxSend(function(event, xhr, ajaxOptions) {
    // do something
});
使用.live()进行绑定更适合我的用例。有可能吗?我在某个地方读到以下代码片段不起作用

jQuery(sourceId).live("ajaxSend", function(event, xhr, ajaxOptions) {
    // do something
});

提前感谢您的回复。

否不可能使用live而不是bind…

您无法使用live()执行此操作,尽管您可能可以使用自定义事件执行此操作

live()的含义是动态添加元素。动态加载的元素必须作为某个事件或AJAX回调的结果来完成,因此在回调事件中,在那里设置新的事件绑定

callback event...
    //code thatadds the new elements...

    jQuery('selector that identifies the new elements').bind("ajaxSend", function(event, xhr, ajaxOptions) {
      // do something
     });
您可能希望将代码包装到函数中

请看这里的评论,抄袭自

.live()技术很有用,但由于其特殊的方法,无法在所有情况下简单地替代.bind()。具体差异包括:


你好,丹尼尔。谢谢是的,我已经从文档中阅读了.live()的评论。好。我会坚持的。那就绑定吧。我在您编写的动态添加/更新的页面中调用.bind()。我想我可以在页面末尾的某个地方做一次,而不在乎绑定到ajaxStart/ajaxComplete的更新页面。但我看到它不起作用,这是不幸的,但浏览器似乎不会在DOM上引发元素的onload事件或on change事件。我想这样做太耗费资源了。
DOM traversal methods are not supported for finding elements to send to .live(). Rather, the .live() method should always be called directly after a selector, as in the example above.
To stop further handlers from executing after one bound using .live(), the handler must return false. Calling .stopPropagation() will not accomplish this.
In jQuery 1.3.x only the following JavaScript events (in addition to custom events) could be bound with .live(): click, dblclick, keydown, keypress, keyup, mousedown, mousemove, mouseout, mouseover, and mouseup.

    As of jQuery 1.4 the .live() method supports custom events as well as all JavaScript events that bubble.
    As of jQuery 1.4.1 even focus and blur work with live (mapping to the more appropriate, bubbling, events focusin and focusout).
    As of jQuery 1.4.1 the hover event can be specified (mapping to mouseenter and mouseleave, which, in turn, are mapped to mouseover and mouseout).