- Download this application skeleton.
- Convert the app to use AJAX.
- Add any files you changed to your gist and submit your code.
-
-
Save milemilo/5872042 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 () { | |
// PSEUDO-CODE: | |
// 1- intercept the form submission event using jQuery | |
$("form").submit(function(){ | |
// 2- prevent the default action for that event from happening | |
event.preventDefault(); | |
// 3- generate a random number between 1 and 6 using JavaScript | |
var rand = Math.floor(Math.random()*6) + 1; | |
// 4- use jQuery to submit an AJAX post to the form's action | |
$.ajax({ | |
type: "POST", | |
url: '/rolls', | |
data: rand, | |
success: function(data) | |
}) | |
// $.post('/rolls', function(rand) { | |
// $('#die').html(rand); | |
//}); | |
// 5- when the AJAX post is done, replace the contents of the "#die" DIV in the DOM using jQuery | |
// $("#die"). | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment