-
-
Save msh345/6617793 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 () { | |
$( "form" ).on( "click", function(event){ | |
event.preventDefault(); | |
var die=Math.floor(Math.random()*6)+1; | |
var url=$('form').attr("action"); | |
$.post(url, die, function(){ | |
$('img').replaceWith("<img src=" + "'" die +".png'>"); | |
}); | |
}); | |
}); |
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
<div class="container"> | |
<h1>Simplest Possible AJAX</h1> | |
<p>This contrived app will simulate a roll of a 6-sided die.</p> | |
<form method="post" action="/rolls"> | |
<input type="submit" value="Roll the Die"> | |
</form> | |
<div id="die"> | |
<% if @roll %> | |
<img src="/<%= @roll.value %>.png" title="<%= @roll.value %>" alt="the roll"> | |
<% else %> | |
<img src="5.png"> | |
<% end %> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment