Primefaces和Ajax成功事件 [英] Primefaces and ajax onsuccess event
问题描述
我将Ajax remoteCommand
组件与Primefaces一起使用,并且此组件使用布尔值更新 inputHidden
字段.
I use ajax remoteCommand
component with Primefaces and this component updates inputHidden
field with boolean value.
我在 remoteCommand
的 onsuccess
事件上调用JS函数,但是似乎在DOM更新之前调用了我的函数,因为当我测试 inputHidden
时值,这不是正确的值,但是如果我将间隔设置为3秒后进行测试,则我具有正确的值...
I call JS function on the onsuccess
event of remoteCommand
but it seems that my function is called before DOM update because when I test inputHidden
value, this is not the right value but if I set interval to test 3s after, I have the right value...
代码:
<p:remoteCommand process="..." onsuccess="hideOrShowNotification();" />
第一次JS测试:
function hideOrShowNotification(){
alert($('#tabView\\:register_form\\:hiddenNotification').val());
}
第二个JS测试:
function hideOrShowNotification(){
setInterval(function(){alert($('#tabView\\:register_form\\:hiddenNotification').val());}, 3000);
}
在第一种情况下,我收到 false
值,在第二种情况下,我收到 true
值.期望值为 true
.
In first case I receive false
value and in second case I receive true
value. The expected value is true
.
因此,当我调用JS函数时,我的DOM并未完全加载.
So my DOM is not fully loaded when my JS function is called.
在DOM完全加载后如何调用JS函数?我相信 onsuccess
事件可以做到这一点,但显然没有.
How can I call JS function after full loading of DOM ? I believed onsuccess
event would do that but no apparently.
推荐答案
好吧...这是 oncomplete
事件.我之前进行过测试,但是也许我忘记了清除浏览器缓存以重新加载新的JS文件.
Ok...it's the oncomplete
event. I tested it before but perhaps I have forgotten to clear browser cache to reload new JS file.
这篇关于Primefaces和Ajax成功事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!