php - Firefox 中的 JQuery SYNC Ajax 调用错误

标签 php jquery ajax firefox asynchronous

我制作了一个无限滚动脚本,效果非常好。但仅限于 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/

相关文章:

javascript - jquery datepicker 返回未定义的值

成功函数后javascript返回数据

javascript - 从内容外部动画侧边栏然后返回

php - 登录到从php触发的exec()命令的文件输出

php - Yii2,抛出 NotFoundException 时出错

php - preg_match() 期望参数 2 为字符串,给出错误的数组

php - 使用 PHP 向 SQL 表添加数据以及如何显示错误

php - 所有其他 AJAX 调用完成后的 jQuery 加载函数

javascript - 捕获目标页面以评估它返回的内容

php - 查询列出表中出现了多少个字符串?