ajax请求到分页结果,如何对ajax请求使用分页

0

我试图在页面上的laravel下设置分页,该页面包含许多可以通过ajax请求过滤的数据。

当我在不过滤页面的情况下转到该页面时,它不会出现问题。但是,当我放置过滤器时,只有第一页显示了良好的数据。以下页面返回未过滤的数据。

我的Ajax搜索路线:

Route::post('search', [FilterController::class, 'filtercentre'])->name('filter.centre');

我的Filtercontroller

public function filtercentre(Request $request) {

$centres = Centre::where('statut', 'Publié')->with('region', 'dept',

'photocentre', 'themes')

->inRandomOrder()

->with('media')

->paginate(4);

if ($request->ajax()) {

return view('frontend.includes.resultcategoriecentre', ['centres' => $centres])->render();

}

return View('frontend.includes.resultcategoriecentre', compact('centres'));

}

我的ajax JS

$(function(){

$('#search').on('submit',function(e){

$.ajaxSetup({

headers: {

'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')

}

});

e.preventDefault(e);

$.ajax({

type:"POST",

url:'/search',

data:$(this).serialize(),

dataType: 'html',

success: function(data){

/// console.log(data);

$( "#submit" ).prop( "disabled", false );

$( "#submit2" ).prop( "disabled", false );

$('#result').empty();

$('#result').html(data);

},

error: function(data){

$( "#submit" ).prop( "disabled", false );

$( "#submit2" ).prop( "disabled", false );

}

})

});

});

过滤器控制器发送带有的模板frontend.includes.resultcategoriecentre

my result

在页面上,我包含了frontend.includes.resultcategoriecentre,并使用.html函数对其进行了刷新。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值