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 );
}
})
});
});
过滤器控制器发送带有
<div id="result">my result</div>
在页面上,我包含了frontend.includes.resultcategoriecentre,并使用.html函数对其进行了刷新。