I am unable to make ajax context work:-
var msgdata = "";
$.ajax({
type: "POST",
url: "players/" + joinplayer + "/joingame.php",
data: {
userID: "<?php echo $_SESSION['username']; ?>",
gameinfo: JSON.stringify(<?php echo json_encode($_SESSION['profile']['user'], true); ?>)
},
context: msgdata,
success: function(data) {
msgdata = data;
$.ajax({
type: "POST",
url: "renamejoin.php",
data: {
userID: "<?php echo $_SESSION['username']; ?>",
joinID: joinplayer
},
context: msgdata,
success: function(data) {
if (data == "" && msgdata != "") {
// sucessfully joined a player's game
} else {
alert(data);
}
},
error: function() {
alert(joinplayer + "'s game is no longer available.");
}
});
},
error: function() {
alert(joinplayer + "'s game is no longer available.");
}
});
if (msgdata == "");
// start showing games awaiting players again
gamefeedrefresh;
timer = window.setInterval(gamefeedrefresh, 2500);
}
msgdata is always "" in this final if statement. The problem seems to be a scope issue but even one or both of the context statements make no difference.
Is it possible to resolve this scope issue? All advice appreciated.