AJAX pagination with Laravel

前端 未结 4 1065
一生所求
一生所求 2020-12-28 09:36

I have this view called posts.blade.php which gets included in home.blade.php:

@foreach ($posts as $po
4条回答
  •  伪装坚强ぢ
    2020-12-28 09:51

    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 link
    var url = $('#search').attr('action')+'?page='+page;
    

提交回复
热议问题