用做于商品详情页的评论展示:
html:
<script> var commodityid=<?php echo $info['commodity_id'] ?>; var url="<?php echo base_url();?>index.php/frontend/ajax_getCommentList?comId="+commodityid+"&per_page=0"; ajax_page(url,commodityid); //点击进行分页 $('.page a').die().live('click',function() { var Href = $(this).attr("href"); //清除上一次加载的html ajax_page(Href,commodityid); //loadtab(Href); return false; }); //ajax显示商品评论 function ajax_page(url,id){ $.ajax({ type:"POST", url:url, dataType:"json", data:"comId="+id, success:function(msg){ $(".info_comment").html(''); for(var i=0;i<msg['commentList'].length;i++){ $(".info_comment").append('<div class="info_comment_item">'+msg['commentList'][i]['username']+':'+msg['commentList'][i]['comment_content']+'</div>'); if(msg['commentList'][i]['comment_reply_content']!=null){ $(".info_comment").append('<div class="info_comment_item"> 回复:'+msg['commentList'][i]['comment_reply_content']+'</div>'); } } $("#pageview").html(msg['page']); } }) } </script>
<div class="info_comment"></div>
CI控制器:
//ajax获取用户评论 public function ajax_getCommentList(){ $this->load->library('pagination'); if($this->input->post('comId')){ $comId=$this->input->post('comId'); }else{ $comId=$this->input->get('comId'); } $num=2; $p=$this->input->get('per_page'); if(empty($p)){ $p=0; } $config['base_url'] =base_url().'index.php/frontend/ajax_getCommentList?comId='.$comId; $config['total_rows'] =$this->frontend_model->comments_like_total($comId); $config['query_string_segmnt']='per_page'; $config['page_query_string']=true; $config['full_tag_open']="<div class='page'>"; $config['per_page']=$num; $config['full_tag_close'] = "</div>"; $this->pagination->initialize($config); $pageview=$this->pagination->create_links(); $p=$this->input->get('per_page'); if(empty($p)){ $p=0; } $commentList=array(); $commentList['page']=$pageview; $commentList['commentList']=$this->frontend_model->get_comment_list($comId,$p,$num); echo json_encode($commentList); }