Skip to content

Instantly share code, notes, and snippets.

@WanaByte
Created January 21, 2013 17:13
Show Gist options
  • Save WanaByte/4587541 to your computer and use it in GitHub Desktop.
Save WanaByte/4587541 to your computer and use it in GitHub Desktop.
Just a basic ajax example which works on JS bin.
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.0.js"></script>
<script>
$(document).ready(function() {
$('a.ajax-trigger').on('click', function(event) {
event.preventDefault(); // Stop the click from going anywhere
$.ajax('/help', {
type: 'GET',
success: function (data, success, jqXHR) {
alert('worked');
$('pre.ajax-data').html(data);
},
failure: function (data, success, jqXHR) {
alert('failed');
$('pre.ajax-data').html(data);
}
});
});
</script>
</head>
<body>
<a class="ajax-trigger" href="#">This will trigger an ajax request</a>
<div>
<pre class="ajax-data"><!-- This will get filled with the data from the request -->
This will be overwritten
</pre>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment