I'm working with Laravel 9 and I wanted to make an infinite loader pagination with ajax for my blade.
So at the Controller:
public function index(Request $request)
{
$ques = Question::orderBy('created_at', 'DESC')->where('que_private',0)->paginate(10);
if($request->ajax()){
$view = view('frontend.layouts.partials.infinite',compact('ques'))->render();
return response()->json(['html' => $view]);
}
return view('frontend.index', compact('ques'));
}
And in the index.blade.php
:
function loadMoreData(page){
$.ajax({
url: '?page=' + page,
type:'get',
beforeSend: function ()
{
$(".ajax-load").show();
}
})
.done(function(data){
if(data.html == ""){
$('.ajax-load').html("");
return;
}
$('.ajax-load').hide();
$("#post-data").append(data.html);
})
.fail(function(jqXHR,ajaxOptions,thrownError){
alert("Server is not responding");
});
}
And this is infinite.blade.php
which ajax loads:
<div id="post-data">
@foreach($ques as $que)
...
@endforeach
</div>
When I test this, the image comes up properly but it returns Server is not responding error alert meaning that .fail(function(jqXHR,ajaxOptions,thrownError){
runs instead.
So what's going wrong here?
开发者_如何学PythonHow can I solve this issue?
精彩评论