javascript - JSF execute Ajax before a onClick Event -


i have javascript function changes position of elements according hiddenfields in document, updated regularly ajax.

problem:

since javascript function (onclick) executed before ajax (which reloads element in hiddenfields are) elements should change position 1 turn behind.

what want achive:

the problem solved if ajax reload executed before onclick event, reference hiddenfields correct. (and not on turn behind)

is possible in way or there solution problem??

code:

call:

                <h:commandbutton id="dice" onclick="animate()" alt="w&uuml;rfel mit einer eins" image="resources/img/wuerfel1.png" action="#{spiel.dice()}" tabindex="4" title="w&uuml;rfel mit einer eins">                     <f:ajax render="gameinfo" />                                             </h:commandbutton> 

javascript function:

    function animate() {         var newplayer1 = document.getelementbyid('player1score').value;         var newplayer2 = document.getelementbyid('player2score').value;         // spieler 1 animation         $("#player1").fadeout(700, function() {             $("#player1").appendto(newplayer1);             $("#player1").fadein(700); });         // spieler2 animation         $("#player2").delay(1400).fadeout(700, function() {             $("#player2").appendto(newplayer2);             $("#player2").fadein(700); });     } 

you should use onevent of f:ajax

  <h:commandbutton id="dice" alt="w&uuml;rfel mit einer eins" image="resources/img/wuerfel1.png" action="#{spiel.dice()}" tabindex="4" title="w&uuml;rfel mit einer eins">       <f:ajax render="gameinfo" onevent="animate" />                               </h:commandbutton> 

change animate function

function animate(data) {     if (data.status === 'success') {         //your original code goes here...     } } 

also : read answer balusc : proccess onclick function after ajax call


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

What is the difference between data design and data model(ERD) -

ios - Can NSManagedObject conform to NSCoding -