【发布时间】:2016-02-09 11:14:49
【问题描述】:
我想在我的由 AJAX 运营的网站中加入分页功能。
我的控制器
public function get_details() {
//pagination
$config = array(
'base_url' => base_url()."exam/create/created/get_details/",
'total_rows' => $this->exam->get_total(),
'first_link' => "First",
'last_link' => "Last",
'per_page' => 5,
'uri_segment' => 5,
'full_tag_open' => "<div id='ajax_pg' class='paginate'>",
'full_tag_close' => "</div>",
'num_tag1_open' => "<a>",
'num_tag1_close' => "</a>",
'cur_tag_open' => "<a class='current'>",
'cur_tag_close' => "</a>",
'next_tag1_open' => "<a>",
'next_tag1_close' => "</a>",
'prev_tag1_open' => "<a>",
'prev_tag1_close' => "</a>",
'first_tag1_open' => "<a>",
'first_tag1_close' => "</a>",
'last_tag1_open' => "<a>",
'last_tag1_close' => "</a>"
);
$page=($this->uri->segment(5) != '') ? $this->uri->segment(5) : 0;
$this->pagination->initialize($config);
$data = array(
'query' => json_encode($this->exam->get_details($page, $config['per_page'])),
'links' => $this->pagination->create_links()
);
echo json_encode($data);
}
我的看法
$(function() {
paginate();
function paginate() {
$('#ajax_pg a').on('click', function() {
var url = $(this).attr('href');
alert(url);
return false;
});
}
});
现在 CI 分页工作正常,但不知何故,我没有触发 ajax jQuery 点击事件。
提前致谢。
【问题讨论】:
标签: php jquery ajax codeigniter pagination