-
-
Save tararoys/7249976 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function () { | |
$("#diceroller").submit(function(){ | |
event.preventDefault(); | |
diceroll = Math.floor(Math.random() * 6) + 1; | |
console.log(diceroll); | |
// var form_data = $("#diceroller").serialize(); | |
var form_data = {"value": diceroll}; | |
console.log(form_data); | |
$.post("/rolls", form_data, function(response){ | |
console.log(response); | |
$("#die").html(response); | |
}); | |
}); | |
// PSEUDO-CODE: | |
// 1- intercept the form submission event using jQuery | |
// 2- prevent the default action for that event from happening | |
// 3- generate a random number between 1 and 6 using JavaScript | |
// 4- use jQuery to submit an AJAX post to the form's action | |
// 5- when the AJAX post is done, replace the contents of the "#die" DIV in the DOM using jQuery | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment