且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

AJAX分页与Laravel

更新时间:2023-02-11 19:16:51

我不是很熟悉的分页中Laravel但判断从你列出的它看起来并不太难的链接。这code是未经考验的,但...

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);
    });
});

更新

在情况下,分页链接是错误的(就像者为OP),你必须自己建立的URL。
只要看看你想要的网址,并添加?页=#号吧。

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;