有没有办法实现一个通用的ajax方法,该方法将为我页面中的每个链接执行?
我的意思是执行像 checkCarousel() 这样的 js 函数,但不需要为我的项目中的每个链接在“oncomplete”ajax 属性上定义它
<p:commandLink action="#{someBean.active}"
update="@all" oncomplete="checkCarousel();" >
<img width="70" src="resources/images/logo.png"
alt="LOGO" style="border: none;"/>
</p:commandLink>
谢谢!
最佳答案
以下是简单的 Google 搜索得到的结果:
PrimeFaces uses under the covers jQuery to deal with ajax requests. So, your best bet is to hook on the generic $.ajaxComplete() handler.
$(document).ajaxComplete(function(event, xhr, options) {
var $source = $("[id='" + options.source + "']");
if ($source.hasClass("myCommandButton")) {
// ...
}
});
The $source represents the jQuery object of the original HTML DOM element on which the ajax action was been triggered, which is in case of this particular example the itself. This offers you the possibility to delegate it further to the desired handler by e.g. examining element's class.
关于javascript - 实现通用的ajax方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25285857/