无法在移动浏览器中在页面滚动上加载数据

时间:2019-04-25 12:36:54

标签: php jquery ajax

滚动页面时,我正在从db获取数据。该代码在桌面浏览器上可以正常运行,但在移动浏览器上不能正常工作。

我从不同的职位尝试了不同的解决方案,但徒劳无功。

$(document).ready(function(){
 $('body').on('touchmove', onScroll);
 $(window).on('scroll', onScroll);
 function onScroll(){
  var lastID = $('.load-more').attr('lastID');
  if(($(window).scrollTop() + window.innerHeight >= document.body.scrollHeight) && (lastID != 0)){
     $.ajax({
        type:'POST',
        url:'getData.php',
        data:'Slno='+lastID,
        beforeSend:function(){
           $('.load-more').show();
        },
        success:function(html){
           $('.load-more').remove();
           $('#postList').append(html);
        }
    });
}
};
});

1 个答案:

答案 0 :(得分:0)

尝试此代码:

$(document).ready(function(){
    $('body').on('touchmove', onScroll);
    $(window).on('scroll', onScroll);
    function onScroll(){
        var lastID = $('.load-more').attr('lastID');
        if ($(window).scrollTop() >  $(document).height() - $(window).height() - 100 && (lastID != 0)) {
            $.ajax({
                type:'POST',
                url:'getData.php',
                data:'Slno='+lastID,
                beforeSend:function(){
                    $('.load-more').show();
                },
                success:function(html){
                    $('.load-more').remove();
                    $('#postList').append(html);
                }
            });
        }
    };
});
相关问题