zoukankan      html  css  js  c++  java
  • CI框架下 ajax分页

    用做于商品详情页的评论展示:

    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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;回复:'+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);
        }
  • 相关阅读:
    20200226 Java IO流——廖雪峰
    20200225 Java 多线程(2)-廖雪峰
    20200225 Java 多线程(1)-廖雪峰
    20200224 尚硅谷ElasticSearch【归档】
    20200224 一 概述
    20200222 尚硅谷Dubbo【归档】
    20200222 四、dubbo原理
    Improved robustness of reinforcement learning policies upon conversion to spiking neuronal network platforms applied to Atari Breakout game
    Reinforcement learning in populations of spiking neurons
    Solving the Distal Reward Problem through Linkage of STDP and Dopamine Signaling
  • 原文地址:https://www.cnblogs.com/houweijian/p/3464981.html
Copyright © 2011-2022 走看看