我打電話給ajax調用,但當我滾動2次其調用重複ajax調用..對於兩個滾動我得到重複ajax call.can任何人都可以幫助我如何糾正重複ajax調用。jQuery ajax無限滾動重複ajax調用
jQuery(function($){
$('#infscr-loading').hide();
$(window).scroll(function() { //detect page scroll
if($(window).scrollTop() == $(document).height() - $(window).height()) {
var key = $(".tab-content div.active").attr("id");
var offset = $(".tab-content div.active .movie_boot .movie-beta__item").length;
var data1 = $("#yr").val();
url = "/loop-movies/?offset="+offset+'&key='+key+'&yr='+data1;
$.ajax({
type : "post",
url : url,
delay : 500,
beforeSend : function(){
$('#infscr-loading').show();
},
success : function(response) {
$(".tab-content div.active .movie_boot").append(response);
$('#infscr-loading').hide();
}
});
}
});
});
你寫Ajax調用,從而滾動 –
我建議使用[無限的,它會調用多次](https://github.com/yairEO/infinite)或[無盡](https://github.com/yairEO/endless)易於使用的插件 – vsync