我正在尝试使用ajax将分页链接放入我的网站,以防止页面刷新。我设法使其工作,但分页链接未更新。当我单击下一页时,将加载该页面,但分页链接将保留在页面1上。这是我的代码:
型号:
$this->pagination->create_links();
控制器:
public function get_posts($limit = FALSE, $rowno = FALSE)
{
if($limit)
{
$this->db->limit($limit, $rowno);
}
$this->db->select('*, posts.image AS post_image, posts.id AS post_id, posts.user_id AS post_user_id');
$this->db->from('posts');
$this->db->join('categories', 'categories.id = posts.category_id');
$this->db->join('users', 'users.id = posts.user_id');
$this->db->order_by('posts.created_at', 'DESC');
$query = $this->db->get();
return $query->result_array();
}
视图:
public function index()
{
// pagination page number
$pageno = $this->input->post('pageno');
// pagination config
// $config['base_url'] = base_url()."posts/index";
$config['base_url'] = '#';
$config['total_rows'] = $this->db->count_all('posts');
$config['per_page'] = 2;
$config['num_links'] = 3;
$config['attributes'] = array('class' => 'pagination-class');
$config['full_tag_open'] = '<div id="paginator">';
$config['full_tag_close'] = '</div>';
$data['posts'] = $this->post_model->get_posts($config['per_page'], $pageno);
$data['title'] = 'Latest Posts';
$data['pagination'] = $this->pagination->create_links();
$data['row'] = $pageno;
// init pagination
$this->pagination->initialize($config);
$this->load->view('posts/index', $data);
}
ajax:
<div id="pagination">
<?php echo $this->pagination->create_links(); ?>
</div>
答案 0 :(得分:0)
可能是您使用了错误的元素ID?
pagination X paginator
?
<div id="pagination"> </div>
$('#pagination') /* .... */