Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@topherPedersen
Last active September 3, 2019 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save topherPedersen/865ca0aa9b10978e97a2fc5787d16517 to your computer and use it in GitHub Desktop.
Save topherPedersen/865ca0aa9b10978e97a2fc5787d16517 to your computer and use it in GitHub Desktop.
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