I have this function, that it’s part of my game, and which sends the data to the getScore.php. And in that php I have some code that sends me back the score for every tag that the player enter, like this “100” “50” or “10.
Now I want to grab those scores and sum them and keep showing the player his score (updating), until the game is over.
function showScore() {
$.ajax({
type: "GET",
url: "getScore.php",
data:{
tag: $("#tag").val(),
timecode: curTime,
filename: getFileName(),
gameid: gameID()
}
}).done(function( msg )
{
show3(msg);
});
return false;
};
The last function is where I show the score, but now I want to change it for sum and show.
How can I do this?!
var score;
function show3(string)
{
document.getElementById('myScore').innerHTML = string;
return string;
}
i’m guessing you want to add the score you get from myScore.php to
scoreand display it. TheparseInt()function should do the trick:firstly, naming the var and the function parameter
scoreis confusing you. Secondly,you weren’t adding the score you got from getScore.php you’re replacing it.