【问题标题】:JQuery SYNC Ajax Calls in Firefox ErrorFirefox 错误中的 JQuery SYNC Ajax 调用
【发布时间】:2012-05-13 21:59:09
【问题描述】:

好吧,我制作了一个无限滚动脚本,效果很好。但只是在 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;
                }                           
            },
        });
    }
}
});

【问题讨论】:

    标签: php jquery ajax firefox asynchronous


    【解决方案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 xD......
    • @IvanSchrecklich - 抱歉,这没有帮助。祝服务器端好运! :)
    猜你喜欢
    • 1970-01-01
    • 2014-11-22
    • 2014-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-20
    • 1970-01-01
    相关资源
    最近更新 更多