1
Hy guys, 我已经做了一个脚本,在滚动发送一些Ajax请求。之后,我将附加响应div。问题是,在滚动击中底部ajax将发送4-5要求改为一个。 我已经设置了一个变量偏移量,每个请求都会增加一个。对于每个请求,我需要选择12个项目。偏移量是计算将被跳过的行数(2 * 12,3 * 12等) 。问题是,有时偏差保持在0和一些请求后,这将增加在滚动加载更多的数据
脚本
$(document).scroll(function(){
if($(window).scrollTop() + $(window).height() > $(document).height() - 500){
string="offset="+offset+'&'+"plusskip="+fistskip;
$('#listaHolder').append('<div class="ajaxLoader"></div>');
$.ajax({
type: "POST",
url: siteURL+"libs/ajax/ajax_foto.php",
data:string,
success:function(response){
offset=offset+1;
fistskip=0;
$('.ajaxLoader').remove();
$('#listaHolder').append(response);
}
});
}
});
关于ajax请求,我选择所有行跳过已经选择的行,例如我第一次选择12 -offset变成1意味着我将跳过12行,对第二个请求偏移成为2意味着我将跳过第一个已经选择的24(12 * 2)行。 – user3677455