Skip to content

Instantly share code, notes, and snippets.

@johnw86
Created August 13, 2012 19:58
Show Gist options
  • Save johnw86/3343691 to your computer and use it in GitHub Desktop.
Save johnw86/3343691 to your computer and use it in GitHub Desktop.
Basic ajax Jquery script for populating list page with next items
<script>
$(function() {
$('a.more').click(function(e) {
e.preventDefault();
var url = $(this).attr('href');
//Show loading symbol
$('.loader').show();
$.get(url, function(data) {
var $data = $(data);
//Find the list on the next page and get children
var items = $data.find('.article_list').children();
var nxtPageLink = $data.find('.paging .next');
if(nxtPageLink.length) {
$('a.more').attr('href', nxtPageLink.attr('href'));
}
else {
$('a.more').hide();
}
//Add the items to our list
$('.article_list').append(items);
//Hide loading
$('.loader').hide();
});
});
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment