Javascript JSF在onClick事件之前执行Ajax
我有一个Javascript函数,它可以根据文档中的一些隐藏字段更改某些元素的位置,这些字段使用ajax定期更新 问题: 由于javascript函数(onclick)是在Ajax之前执行的(Ajax重新加载hiddenfields所在的元素),因此应该改变位置的元素总是落后一圈 我想要实现的目标: 如果在onclick事件之前执行ajax重载,那么问题就会得到解决,因此对hiddenfields的引用是正确的。(且不在后面转弯) 这在任何方面都是可能的,或者这个问题还有其他解决方案吗 代码: 电话:Javascript JSF在onClick事件之前执行Ajax,javascript,html,ajax,jsf,facelets,Javascript,Html,Ajax,Jsf,Facelets,我有一个Javascript函数,它可以根据文档中的一些隐藏字段更改某些元素的位置,这些字段使用ajax定期更新 问题: 由于javascript函数(onclick)是在Ajax之前执行的(Ajax重新加载hiddenfields所在的元素),因此应该改变位置的元素总是落后一圈 我想要实现的目标: 如果在onclick事件之前执行ajax重载,那么问题就会得到解决,因此对hiddenfields的引用是正确的。(且不在后面转弯) 这在任何方面都是可能的,或者这个问题还有其他解决方案吗 代码:
您应该使用
f:ajax的onevent
<h:commandButton id="dice" alt="Würfel mit einer Eins" image="resources/img/wuerfel1.png" action="#{spiel.dice()}" tabindex="4" title="Würfel mit einer Eins">
<f:ajax render="gameinfo" onevent="animate" />
</h:commandButton>
另外:请阅读BalusC的回答:
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);
});
}
<h:commandButton id="dice" alt="Würfel mit einer Eins" image="resources/img/wuerfel1.png" action="#{spiel.dice()}" tabindex="4" title="Würfel mit einer Eins">
<f:ajax render="gameinfo" onevent="animate" />
</h:commandButton>
function animate(data) {
if (data.status === 'success') {
//your original code goes here...
}
}