Skip to content

Instantly share code, notes, and snippets.

@harishraisinghani
Created August 23, 2016 04:53
Show Gist options
  • Save harishraisinghani/35f8702363b5475ced1403572119ade7 to your computer and use it in GitHub Desktop.
Save harishraisinghani/35f8702363b5475ced1403572119ade7 to your computer and use it in GitHub Desktop.
W6D1 - Ajax Example
<!doctype html>
<html>
<head>
<title> Ajax Example </title>
</head>
<body>
<section>
<h1>Recent Posts </h1>
<article>
<h2>Post 1</h2>
<p>This is post 1.</p>
</article>
<article>
<h2>Post 2</h2>
<p>This is post 2.</p>
</article>
<article>
<h2>Post 3</h2>
<p>This is post 3.</p>
</article>
<button id="load-more-posts">Load More Posts</button>
</section>
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script>
$(function() {
var button = $('#load-more-posts');
button.on('click', function() {
$.ajax({
url: 'more-posts.html',
method: 'GET',
success: function(morePostsHtml) {
button.replaceWith(morePostsHtml);
}
});
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment