中止来自jsf.ajax.addOnEvent()的JSF Ajax请求 [英] Aborting JSF Ajax Request from jsf.ajax.addOnEvent()

查看:110
本文介绍了中止来自jsf.ajax.addOnEvent()的JSF Ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一个中央位置监视ajax请求,并在某些情况下中止它们.

I would like to have a central place where I monitor ajax requests and in certain situations abort them.

我唯一不知道要做的就是实际上中止来自一个中央函数的ajax请求.

The only thing I don't know to do is to actually abort the ajax request from one central function.

我想像一下解决方案看起来像这样:

I Imagine that the solution would look something like this:

jsf.ajax.addOnEvent(function(data) { 
    if (data.status === 'begin') {
        // abort the ajax request
    }
});

但是我可能会误会了.

谢谢!

推荐答案

标准

This is not possible by the standard JSF JS API. Your best bet is to add an onclick or onchange handler on the calling JSF component which returns false if the desired condition is met to abort the ajax request.

<h:commandButton onclick="return mayFireAjax(this)">
    <f:ajax />
</h:commandButton>

如有必要,您可以使用 jQuery.on() (或 jQuery.live() (取决于所使用的jQuery版本)在一个公共选择器上,这样您就不必在每个所需的组件上重复它.

You can if necessary abstract this away with jQuery.on() (or jQuery.delegate() or jQuery.live() depending on the jQuery version used) on a common selector so that you don't need to repeat it on every desired component.

$(someSelector).on("click", function() {
    return mayFireAjax(this);
});

这篇关于中止来自jsf.ajax.addOnEvent()的JSF Ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆