Javascript 在scroll laravel ajax上加载更多数据
我在youtube上跟踪代码,一切正常,但当我连续滚动鼠标最后一页加载重复多次时,有人可能会帮我修复此错误,我正在修正它Javascript 在scroll laravel ajax上加载更多数据,javascript,ajax,laravel,pagination,Javascript,Ajax,Laravel,Pagination,我在youtube上跟踪代码,一切正常,但当我连续滚动鼠标最后一页加载重复多次时,有人可能会帮我修复此错误,我正在修正它 <div class="product endless-pagination" data-next-page="{{$product->nextPageUrl()}}" data-last-page="{{$product->lastPage()}}"> @include('user.blocks.d_test')
<div class="product endless-pagination" data-next-page="{{$product->nextPageUrl()}}" data-last-page="{{$product->lastPage()}}">
@include('user.blocks.d_test')
</div>
<script type="text/javascript">
$(document).ready(function () {
$(window).scroll(fetchPost);
function fetchPost() {
var page = $('.endless-pagination').data('next-page');
//var lastpage=$('.endless-pagination').data('last-page');
if (page !== null && page.length > 0) {
$('.loading').show();
if ($(window).height()+ $(window).scrollTop()+100 >= $(document).height()) {
clearTimeout($.data(this, "scrollCheck"));
$.data(this, "scrollCheck", setTimeout(function () {
$.get(page, function (data) {
$('.endless-pagination').data('next-page', data.next_page);
$('.loading').hide();
$('.product').append(data.product);
})
}, 350))
}
}
}
})
</script>
@包括('user.blocks.d_test')
$(文档).ready(函数(){
$(窗口)。滚动(fetchPost);
函数fetchPost(){
var page=$('.无尽分页')。数据('next-page');
//var lastpage=$('.fully pagination')。数据('last-page');
如果(page!==null&&page.length>0){
$('.loading').show();
if($(窗口).height()+$(窗口).scrollTop()+100>=$(文档).height()){
clearTimeout($.data(这是“滚动检查”);
$.data(此“滚动检查”,setTimeout(函数(){
$.get(页面,函数(数据){
$('.fully pagination').data('next-page',data.next_page);
$('.loading').hide();
$('.product').append(data.product);
})
}, 350))
}
}
}
})
您应该试试本教程。它适合我,你不必再发明轮子:
谢谢,我也尝试过,但在laravel 5.6上不起作用