开发者

$(document).ready() doesn't run after f:ajax rendering

I have some jQuery code that runs on every $(document).ready() event. I also have some <f:ajax> tags that do re-rendering开发者_StackOverflow社区 of some parts of the page.

I noticed that when I rerender a component, the $(document).ready() doesn't get called.

Is there a way to run javascript code after every <f:ajax> rerendering? (I can technically use the onevent tag but that's the unfavourable solution to me since I will have to call the function on every <f:ajax>)

Just for illustration, this is the jQuery Code:

$(document).ready(function() { ...CODE... }

And the JSF code:

<f:ajax event="click" render=":someComponentID"/>

Thanks!

UPDATE This question might be a duplicate of this one. I'm looking into it.

UPDATE2 This is easily solvable using the JSF Javascript event binding:

jsf.ajax.addOnEvent(function(data){
  if (data.status === 'success') {
    // Do stuff here
  }
}

Read more about it under the JSF 2 reference


The $(document).ready() event fires once, when the DOM has fully loaded from the initial load.

An ajax event may change the DOM, but it doesn't reload the page, so the $(document).ready() won't fire again.

I noticed the way Google solved this problem in Gmail is by using a high frequency timer.


Use events and listeners..

Have a read at Ajax tag events and listeners

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜