Skip to content

Instantly share code, notes, and snippets.

@mikedhart
Created December 18, 2015 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikedhart/9c9ffbeb491b44fb768b to your computer and use it in GitHub Desktop.
Save mikedhart/9c9ffbeb491b44fb768b to your computer and use it in GitHub Desktop.
Event listener/AJAX example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<a href="#" id="click_me">Click me</a>
<div id="response_holder">Nothing here!</div>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript" charset="utf-8">
$(document).on('ready', function (e) {
$('#click_me').on('click', function (e) {
url = "/";
$.ajax({
method: 'get',
url: url,
data: {
aidan: 'cool',
mike: 'un-cool'
},
success: function (resp) {
alert('Yay');
//$('#response_holder').html(resp);
},
error: function (xhr) {
alert('Nay!');
}
});
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment