手机端 jQuery ajax下拉自动加载数据

var loadingdelay = false;  // 此处参数是判断是否重复的请求 避免数据多加载

$(window).on("scroll", function(event) {

    var h = $(document).height();

    var wh = $(window).height();

    if ($(window).scrollTop() >= h - wh - 100 && !loadingdelay) {

        loadingdelay = true;

        //发送Ajax

        var page = $('#ajax').attr('data');

        $.ajax({

            type: "POST",

            url:'',

            cache:false,

            data:{page:page},

            dataType:'html',

            success: function(data) {

                if(data.length){

                    $('#ajax').append(data);

                    page++;

                    $('#ajax').attr('data-page',page);

                    loadingdelay = false;

                }else{

                    loadingdelay = false;

                    return false;

                }

            }

        });

    }

});

// div 结构

你可能感兴趣的:(手机端 jQuery ajax下拉自动加载数据)