Skip to content

Instantly share code, notes, and snippets.

@milemilo
Forked from dbc-challenges/lucky_ajax.md
Last active December 19, 2015 00:58
Show Gist options
  • Save milemilo/5872042 to your computer and use it in GitHub Desktop.
Save milemilo/5872042 to your computer and use it in GitHub Desktop.
$(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").
});
});

Instructions:

  1. Download this application skeleton.
  2. Convert the app to use AJAX.
  3. Add any files you changed to your gist and submit your code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment