Created
August 13, 2012 19:58
-
-
Save johnw86/3343691 to your computer and use it in GitHub Desktop.
Basic ajax Jquery script for populating list page with next items
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
<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