AJAX pagination with Laravel AJAX pagination with Laravel ajax ajax

AJAX pagination with Laravel


I'm not very familiar with pagination in Laravel but judging from the links you listed it doesn't look too hard. This code is untested though...

$('#pagination a').on('click', function(e){    e.preventDefault();    var url = $(this).attr('href');    $.post(url, $('#search').serialize(), function(data){        $('#posts').html(data);    });});

Update

In case the pagination links are wrong (like the were for the OP) you have to build the url by yourself.
Just take the url you want and add ?page=#number to it.

// page being the page number stripped from the original linkvar url = $('#search').attr('action')+'?page='+page;


I am using following js for getting data on href click.

// Your Local url var Url = 'laraveltestproject/laravelpagination';$('#ajaxContent').load("Url");$('.pagination a').on('click', function(event) {    event.preventDefault();    if ($(this).attr('href') != '#') {        $('#ajaxContent').load($(this).attr('href'));    }});

For Complete example you can visit the http://www.tutsway.com/laravel-ajax-pagination-example.php.


I have the perfect tool for the job. Please check out this repo https://github.com/themightysapien/ajaxtable

Please read the docs it is very easy to use and is specially made for laravel. All you need to do is return your results as following example.

return Response::json(array(              'data'=> View::make('only_table_row_view', compact('collection')->render(),              'pagination'=>(string) $collection->links()              ));

Required files are add

<link rel="stylesheet" href="css/ajaxtable.css"><script src="js/plugins.js"></script>$(".yourtable").ajaxtable();

Initialize your ajax url through data-requestUrl attribute in your table.Add a id="paginationWrapper" div in your page where you want your pagination to appear.

If you have any problem run the repo in your local server and see the source for html markups and plugin options.