使用上的JavaScript(前,后)每次的Ajax调用JavaScript、Ajax

2023-09-10 17:37:34 作者:可爱污女的萌大叔

由于我与 TinyMCE的工作(请不要进入Primefaces有一个编辑器或类似的话),我需要执行一小片 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).

推荐答案

使用的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目标=头> < 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.

 
精彩推荐
图片推荐