控制器
public function index(){ $tid = I("get.tid"); //产品分类id if($tid==""){ $tid = M("Proclass")->where(array('pid'=>1,'lang'=>$this->lang))->order("orderby asc")->getField("id"); } //分类名称 $type_name = M("Proclass")->where(array('id'=>$tid))->getField("proclassname"); $type_id = M("Proclass")->where(array('id'=>$tid))->getField("id"); if($tid==1){ $type_name='所有产品'; } $this->assign("type_name",$type_name); $this->assign("type_id",$type_id); //产品列表 $pro_data = $this->getPro($tid,$this->lang,0,1,1,4); $this->assign("pro_data",$pro_data); $this->display(); } public function prolist_ajax(){ $start = I("get.start"); $tid = I("get.tid"); //查询分类下子分类 if($tid==""){ $tid=2; } $proarr = M("Proclass")->select(); $proTypeAllId = Getcate::getChildsId($proarr,$tid); $proTypeAllId[]=$proTypeId; //查询条件 $where['cid']=array('in',$proTypeAllId); $where['isshow']=1; //总条数 $total_count = M("Product")->where($where)->order("orderby ASC")->count(); //每页条数 $size = 4; //总页数 $total_pages = ceil($total_count/$size); if($start<=$total_pages){ $data = M("Product")->where($where)->limit(($start-1)*$size,$size)->order("orderby ASC")->select(); } //改变日期格式 foreach($data as $k=>$vo){ $data[$k][type_id] = M("Proclass")->where(array('id'=>$vo[cid]))->getField("id"); } echo json_encode($data); // $this -> ajaxReturn($data); }
index.php
<div class="w1200 main cr"> <div class="tit"><span class="sp-cn"><{$type_name}></span></div> <ul class="case"> <volist name="pro_data" id="vo"> <li> <a href="<{:U('Product/proinfo',array('id'=>$vo[id],'pid'=>$type_id))}>"> <img src="__PUBLIC__/Uploads/Product/<{$vo.prophoto}>" alt=""> <div class="mask"><span class="litit"><{$vo.proname}></span></div> </a> </li> </volist> </ul> <div class="cr"></div> <a href="javascript:;" class="more" onclick="jzgd(<{$Think.get.tid}>)">探索更多</a> </div> ---------------------------------------- <script type="text/javascript"> var $start=2; function jzgd(tid){ var start=$start; var tid=tid; var pro_str = ''; $.get("<{:U('Product/prolist_ajax')}>",{start:start,tid:tid},function(data){ if(data==null){ alert("已经没有更多数据啦!"); return false; }; $.each(data,function(k,v){ pro_str += '<li><a href="http://localhost/yonggu2/web/index.php?s=/Product/proinfo/id/'+v.id+'/pid/'+v.type_id+'"><img src="__PUBLIC__/Uploads/Product/'+v.prophoto+'" alt=""><div class="mask"><span class="litit">'+v.proname+'</span></div></a></li>'; }) $(".case").append(pro_str); $start++; },'JSON'); } </script>