Codeigniter使用ajax分页

时间:2014-02-11 04:53:39

标签: php jquery ajax codeigniter pagination

我使用codeigniter

使用ajax分页
<script>
$("div.review_pagination a").click(function(){
    var reviews_url=$(this).attr("href");
    alert(reviews_url);
    readmore_after5(); 
    $.post( reviews_url,{product_id:<?php echo $product->id;?> }
        ,function( data ){

     $('#review_pagination').html(data);   
    },"html");

    return false;
 });   

    });
</script>

这是我的视图页面

<div class="span12" id="review_pagination">
        <!-- load the ajax call-->

        <?php echo $this->load->view('reviews_list');?>

          </div>

 $data['reviews']= $this->Product_model->get_reviews($id,$limit,$start);
 $data['total']= $this->Product_model->get_reviews_count($id,$term);

下面是分页,分页问题不仅是'2',如果我像2,3,4,5,6数据即将到来但分页活跃不会从1变为2,3,4,5 ,6因此基于数据加载

$this->load->library('pagination');

  $config['base_url'] = base_url().'myaccount/ajax_reviews_data';
  $config['total_rows']     = $data['total'];
  $config['per_page']       = $rows;
  $config['uri_segment']        = 5;
  $config['first_link']     = 'First';
  $config['first_tag_open'] = '<li>';
  $config['first_tag_close']    = '</li>';
  $config['last_link']      = 'Last';
  $config['last_tag_open']  = '<li>';
  $config['last_tag_close'] = '</li>';
  $config['prev_link']                = '&lt;';
  $config['full_tag_open']  = '<div class="pagination review_pagination"><ul>';
  $config['full_tag_close'] = '</ul></div>';
  $config['cur_tag_open']       = '<li class="active"><a href="#">';
  $config['cur_tag_close']  = '</a></li>';
  $config['prev_link']                = '&lt;';
  $config['prev_tag_open']        = '<li>';
  $config['prev_tag_close']        = '</li>';
  $config['num_tag_open']       = '<li>';
  $config['num_tag_close']  = '</li>';
  $this->pagination->initialize($config);
  //$data['video_reviews']= $this->Product_model->get_video_reviews($id);
  if(isset($_GET['v'])&&$_GET['v']==1)
      $data['show_video_review']=1;
  else   
     $data['show_video_review']=0;

$this->template->write_view('content', 'product',$data, TRUE);
$this->template->render();

1 个答案:

答案 0 :(得分:0)

我无法告诉您发布的代码中的所有内容,但请记住,分页链接是分页库的输出,而您的结果是模型的输出(+ html格式化)

听起来像你在ajax响应中返回结果,而不是新的分页库输出。

当您对其进行排序时,您应该将您的代码带到CI论坛进行代码审查,因为您似乎在如何安排人们可以帮助您的代码方面犯了很多错误,但也是如此该线程很长时间进入