jQuery+AJAX实现无刷新分页滚动下拉加载

$(function(){

    var page = 1;
    var innerHeight = window.innerHeight;
    var timer2 = null;

    var dynamictype = getUrlParam('account');
    var tcontent = getUrlParam('tcontent');
    var start = getUrlParam('start');
    var end = getUrlParam('end');
    var uid = getUrlParam('uid');

    $.ajax({
        type: 'POST',
        url: pnUrl()+"xxxxx/dynamicList",
        data: {tcontent:tcontent,uid:uid,dynamictype:dynamictype,start:start,end:end,page:page},
        timeout: '5000',
        cache: 'false',
        dataType: 'json',
        success: function(data){
            if (data.success == true) {
                   var result = '';

                  for(var i=0;i < data.data.list.length; i++){

                          result += '';

                  }

                  $('.dylist').append(result);
            }

             var p=0,t=0;
             $(window).scroll(function(e) {
                   clearTimeout(timer2);
                    timer2 = setTimeout(function() {
                              p = $(this).scrollTop();
                              page++;
                              if(t<=p){//下滚  
                                        $.ajax({
                                        type: 'POST',
                                        url: pnUrl()+"xxxxx/dynamicList",
                                        data: {tcontent:tcontent,uid:uid,dynamictype:dynamictype,start:start,end:end,page:page},
                                        dataType: 'json',
                                        success: function(data){
                                                if(data.success==true){
                                                        var result = '';
                                                        for(var i=0;i < data.data.list.length; i++){

                                                                result += '';
                                                        }
                                                     $('.dylist').append(result);
                                                }else{
                                                      $(window).unbind('scroll');
                                                }
                                          }
                                    });
                              }else{ } //上滚
                        t = p;
                   }, 200);
             }) 

        },error:function(data){

        }
    });

});

你可能感兴趣的:(Javascript,Jquery)