我制作了一个无限滚动脚本,效果非常好。但仅限于 Chrome 和 IE。不幸的是,它不会在 Firefox 上执行同步调用,但仍然会影响服务器异步...这意味着我收到了大量不应该请求的内容...因为我在谷歌上搜索并没有找到明确的解决方案对于我的问题,所以我会问你们:
var endajax = 0;
$(window).scroll(function(){
if (endajax == 0)
{
if($(window).scrollTop() + $(window).height() > $(document).height() - 405)
{
$('#profilecontent').prepend('<div class="iloader bgtrans padding ui-corner-all" style="position: fixed; bottom: 20px; right: 80px;"><div class="ui-widget-content ui-corner-all padding"><img width="8" src="images/loader.gif" alt="" /> Inhalt wird nachgeladen, bitte einen Moment gedulden</div></div>');
var firstid = $('.postbox').last().attr('name');
var lastid = $('.postid').last().val();
var data = "firstid="+firstid+"&lastid="+lastid+"&uid=<?php echo $profileuser->id; ?>";
setTimeout(function() {
$('.iloader').remove();
}, 2000);
$.ajax({
url: "modules/users/profile/profileposts.php",
cache: false,
type: "POST",
async: false,
data: data,
success: function(data){
if (data.length != 2) {
$('#profileposts').append(data).fadeIn('slow');
}
else
{
endajax = 1;
}
},
});
}
}
});
最佳答案
也许在 ajax 调用之前锁定你的信号量?
if($(window).scrollTop() + $(window).height() > $(document).height() - 405)
{
endajax++;
然后
success: function(data){
if (data.length != 2) {
endajax = 0;//or 1 depending on how you are locking this control out
$('#profileposts').append(data).fadeIn('slow');
}
关于php - Firefox 中的 JQuery SYNC Ajax 调用错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10575591/