Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add to Leaderboard AJAX Script
// Guys, we need to write a little javascript here
// to add the user's score to our database
var playerName = "nUb";
var score = points;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// document.getElementById("demo").innerHTML = this.responseText;
alert(this.responseText);
}
};
xhttp.open("POST", "add_score_to_leaderboard.php", true);
var myFormData = new FormData();
myFormData.append("playerName", playerName);
myFormData.append("score", score);
xhttp.send(myFormData);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.