Easy ajax pagination

Submitted by riddles8888 - 10 years ago

Use laravel pagination with this small bit of jquery to ajax load paginated results. Create a page with the data you wish to paginate. http://www.example.com/paginated/data

<div id="ajaxContent">
</div>

<script>
$('#ajaxContent').load('http://www.example.com/paginated/data');

$('.pagination a').on('click', function (event) {
    event.preventDefault();
    if ( $(this).attr('href') != '#' ) {
        $("html, body").animate({ scrollTop: 0 }, "fast");
        $('#ajaxContent').load($(this).attr('href'));
    }
});
</script>