jQueryスライド下部に次のページのデータをロードするインスタンスコード

3522 ワード

くだらないことは言わないで、直接みんなにコードを貼って、具体的なコードは以下の通りです.

page_num =page_num+1 ; //      ,            。
      $.ajax({
        type: "get",  
        url: rent_url, 
        data: '2',
        dataType: "json",
        success: function (data) {
//                  
          rentDataNum = data.count
//             6          
          rentDataPagge = Math.ceil(rentDataNum/6);
          $(".loaddiv").hide();
//                   0               html           
          if (data.houses.length > 0) {
            insertDiv(data.houses,rentDataPagge,pagenumber);
          }
        },
        beforeSend: function () {
          $(".loaddiv").show();
        },
        error: function (data) {
          $(".loaddiv").hide();
        }
      });
    }
    //          
      getData(1);
    //    html,append div 
    function insertDiv(data,page_num,pagenumber) {
      var $mainDiv = $(".er_list");
      var result = '';
      if (pagenumber<=page_num){
        for (var i = 0; i < data.length; i++) {
          var houe_title   =  data[i].community_name != undefined ? data[i].community_name:data[i].business_area_name;
          result +='<li>';
          result +='<a href="#" rel="external nofollow" >'
          result +='<div class="img_left"><img src='+"http://image.5i5j.com/picture/slpic/l"+data[i].img_url+'></div>'
          result +='<div class="img_con">'
          result +='<h5>'+houe_title+'</h5>'
          result +='<p class="ting">'+data[i].bedroom+'  '+ data[i].livingroom+'  1 <span>·</span>'+data[i].buildarea+' �O<span>·</span>  </p>'
          result +='<p class="info">'+data[i].district_name+'</p>'
          result +='<p class="tag">'
          result +='<em class="yell_01">   </em><em class="yell_02">   </em><em class="yell_03">   </em><em class="yell_04">   </em>'
          result +='</p>'
          result +='<div class="jia"><p>'+data[i].price+' </p><span>123 /�O</span></div>'
          result +='</div>'
          result +='</a>'
          result +='</li>';
        }
        $mainDiv.append(result);
        //                    
        if (pagenumber==page_num){
          $("div").remove('#loadings')
        }
      }
    }
    //==============    =============
    var winH = $(window).height(); //        
    var scrollHandler = function () {
      var pageH = $(document.body).height();
      var scrollT = $(window).scrollTop(); //   top
      var aa = (pageH - winH - scrollT) / winH;
      if (aa < 0.02) {//0.02    
        //                     
        if (page_num<=rentDataPagge+1){
          //                
          getData(page_num);
        }
      }
    }
    //        
    $(window).scroll(scrollHandler);
    //==============    =============
    //        
    $("#btn_Page").click(function () {
      getData(page_num);
      $(window).scroll(scrollHandler);
    });
  });