使用上的JavaScript(前,后)每次的Ajax调用 [英] Javascript on (before and after) every Ajax-call

查看:160
本文介绍了使用上的JavaScript(前,后)每次的Ajax调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我与 TinyMCE的工作(请不要进入Primefaces有一个编辑器或类似的话),我需要执行一小片<$的C $ C> Javascript的之前和之后的每一个阿贾克斯 -call。我想preFER不要编辑每个阿贾克斯 -call对于这一点,因为有很多的(而且这样做将是未来维护不好的做法)。

Since I'm working with TinyMCE (please don't go into "Primefaces has an editor" or anything similar) I need to execute a small piece of Javascript before and after every Ajax-call. I'd prefer not to edit every Ajax-call for this since there are a lot (and doing so will be bad practice for any future maintenance).

什么是最完美的解决方案来执行 Javascript的 pre型和后任何阿贾克斯 -call在网页上?

What would be the most elegant solution to execute Javascript pre- and post- any Ajax-call on the page?

注:我使用的是自定义的复合 TinyMCE的 -textarea。任何事件也该对象也就够了。虽然记住,实际阿贾克斯 -trigger可能是由一个完全不同的对象调用(虽然仍可以重新呈现的复合

Note: I'm using a custom composite for the TinyMCE-textarea. Any events too this object would also suffice. Though keep in mind that the actual Ajax-trigger might be invoked by a totally different object (though could nevertheless rerender the composite).

推荐答案

使用的<一个href="https://javaserverfaces.java.net/nonav/docs/2.1/jsdocs/symbols/jsf.ajax.html#.addOnEvent"><$c$c>jsf.ajax.addOnEvent处理程序。

Use the jsf.ajax.addOnEvent handler.

jsf.ajax.addOnEvent(function(data) {
    switch(data.status) {
        case "begin":
            // This is invoked right before ajax request is sent.
            break;

        case "complete":
            // This is invoked right after ajax response is returned.
            break;

        case "success":
            // This is invoked right after successful processing of ajax response and update of HTML DOM.
            // In case you're interested in error handling, use jsf.ajax.addOnError handler.
            break;
    }
});

只是把它放在其中包括℃的JS文件; H:outputScript目标=头&GT; &LT; H :身体GT; 所需的页面。这将确保它的加载的的JSF自己的 jsf.js 包含 JSF 命名空间。

Just put it in a JS file which is included by <h:outputScript target="head"> in the <h:body> of the desired pages. This will ensure that it's loaded after JSF's own jsf.js containing the jsf namespace.

这篇关于使用上的JavaScript(前,后)每次的Ajax调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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