Thursday, 22 August 2013

JQuery .ajax dont call function

JQuery .ajax dont call function

I have object "game" and when i call create game, its use jquery ajax...
everything works ok, but when i want to call from ajax success function
addLoadEvent it doesnt call it, when i try call this function from
createGame (commented part of code here) its works... do you know why i
cant call it from ajax success? i try console log from success and it was
print in console so ajax works well. Thank everybody for help
var game=new ttt_game();
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
function ttt_game () {
this.createGame = createGame;
function createGame(){
/*addLoadEvent(function(){
document.getElementById('player1_n').textContent=player1+':';
document.getElementById('player2_n').textContent=player2+':';
document.getElementById('turn').textContent='Èaká
sa na príchod súpera.';
});*/
$.ajax({
type: "POST",
url: "process.php",
data: {'function': 'create','game_id':
game_id,'player1': player1},
dataType: "json",
success: function(data){
addLoadEvent(function(){
document.getElementById('player1_n').textContent=player1+':';
document.getElementById('player2_n').textContent=player2+':';
document.getElementById('turn').textContent='Èaká
sa na príchod súpera.';
});
},
error: function(jqXHR, textStatus, errorThrown) {
alert(errorThrown);
}
});
}
}
game.createGame();

No comments:

Post a Comment