我在异步调用发生后使用自定义触发事件,我需要一种方法来确定它们何时全部被触发。
例如:
var ajaxFunction1 = function(){
$.ajax({
url: "someUrl.html",
complete: function(){
//Ok, all done
$(document).trigger('ajaxFunction1Finished')
}
})
}
var ajaxFunction2 = function(){
$.ajax({
url: "someUrl.html",
complete: function(){
//Ok, all done
$(document).trigger('ajaxFunction2Finished')
}
})
}
var ajaxFunction3 = function(){
$.ajax({
url: "someUrl.html",
complete: function(){
//Ok, all done
$(document).trigger('ajaxFunction3Finished')
}
})
}
ajaxFunction1();
ajaxFunction2();
ajaxFunction3();
jQuery
.when( /* Whenever $(document) receives those three events */ )
.done(function(){
//Do something
})
这可能吗?我想避免触发新事件只是为了获得回报。