Php 使用ajax分页获取查询字符串

Php 使用ajax分页获取查询字符串,php,laravel,octobercms,Php,Laravel,Octobercms,我知道,当您添加类似于->appends(['location'=>$search])的内容时,可以进行查询。使用分页时,它甚至可以将搜索查询保留到下一页。现在我使用ajax进行分页,我有这个js代码 <script type="text/javascript"> //Pagination part $('.main-section').on('click', '.pagination > li > a', function (event) { var

我知道,当您添加类似于
->appends(['location'=>$search])
的内容时,可以进行查询。使用分页时,它甚至可以将搜索查询保留到下一页。现在我使用ajax进行分页,我有这个js代码

<script type="text/javascript">

//Pagination part
    $('.main-section').on('click', '.pagination > li > a', function (event) {
    var page = $(this).text();
    event.preventDefault();
    if ($(this).attr('href') != '#') {
        $("html, body").animate({scrollTop: 0}, "slow");
        $.request('onFilterProduct', {
            data: {page: page},

        });
    }
});
</script>

当我加载第一个页面时,这一切都可以正常工作并获得正确的页码,但是当我单击第二个页面时,它会重置所有内容,并且分页不再适用于位置查询字符串。请问我该怎么修

Well最终找到了一个解决方案,该解决方案使用javascript pushState api更新页面url而无需重新加载

 history.pushState(null, null, $(this).attr('href')); 
所以我的js代码现在看起来像这样

<script type="text/javascript">

//Pagination part
    $('.main-section').on('click', '.pagination > li > a', function (event) {
    var page = $(this).text();
    event.preventDefault();
    if ($(this).attr('href') != '#') {

        // Update the browser's address bar
        history.pushState(null, null, $(this).attr('href'));  

        $("html, body").animate({scrollTop: 0}, "slow");
        $.request('onFilterProduct', {
            data: {page: page},

        });
    }
});
</script>

//分页部分
$('.main section')。在('click','.pagination>li>a',函数(事件){
var page=$(this.text();
event.preventDefault();
if($(this.attr('href')!='#'){
//更新浏览器的地址栏
history.pushState(null,null,$(this.attr('href'));
$(“html,body”).animate({scrollTop:0},“slow”);
$.request('onFilterProduct'{
数据:{page:page},
});
}
});
<script type="text/javascript">

//Pagination part
    $('.main-section').on('click', '.pagination > li > a', function (event) {
    var page = $(this).text();
    event.preventDefault();
    if ($(this).attr('href') != '#') {

        // Update the browser's address bar
        history.pushState(null, null, $(this).attr('href'));  

        $("html, body").animate({scrollTop: 0}, "slow");
        $.request('onFilterProduct', {
            data: {page: page},

        });
    }
});
</script>