Controller类创建方法
publicfunctionajaxindex($p,$cid){ $articlecate=M('articlecate'); $article=M('article'); $listRows=6; $firstRow=($p-1)*$listRows; $data=$article->where("cateidin(".$cid.")")->limit($firstRow,$listRows)->field("id,title,pic,time,des")->select(); echojson_encode($data); }
页面js输出
<scriptlanguage="javascript"> $(window).on("scroll",function(){ if($(document).scrollTop()>=400){ $('.imoreBox').click(); } }) varpage=1; functiongetlist(page){ $.ajax({ type:"GET",url:"__CONTROLLER__/ajaxindex/p/"+page+"/cid/<?PHPechoI('get.cid');?>",dataType:"json",success:function(data){ if(data==null||data==''){ $("#imore").html('没有了'); $("#imore").unbind("click"); } varhtml=""; $(data).each(function(k,v){ html+='<li><divclass="news_title"><ahref="/index.PHP/Wap/News/info/id/'+v.id+'">'+v.title+'</a></div><divclass="news_des"><ahref="/index.PHP/Wap/News/info/id/'+v.id+'">'+v.des+'</a></div></li>'; }); $("#ajaxBox").append(html); } }); } getlist(1); $("#imore").click(function(){ getlist(++page); }); </script>