控制器:
public function management_colleges($offset=null)
{
$config['base_url'] = base_url().'management_college';
$total = $this->field->management_count();
$config['total_rows'] = $total['count_rows'];
$config['per_page'] = 10;
$config['full_tag_open'] = '<ul class="pagination" id="search_page_pagination">';
$config['full_tag_close'] = '</ul>';
$config['cur_tag_open'] = '<li class="active"><a href="javascript:void(0)">';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_close'] = '</a></li>';
$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['next_link'] = FALSE;
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['prev_link'] = FALSE;
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['page_query_string'] = FALSE;
$this->pagination->initialize($config);
$data['management'] = $this->field->management($config['per_page'],$offset);
$this->load->view('management-colleges', $data);
}
观点:
<div id="container">
<div id="body">
<ul id="ul">
<?php
foreach ($management as $fetch)
{
?>
<li>
<?php echo $fetch['college_name']; ?>
</li>
<?php
}
?>
</ul>
<?php
echo $this->pagination->create_links();
?>
</div>
</div>
<script type="text/javascript">
$(function(){
$('body').on('click','ul#search_page_pagination>li>a',function(e){
e.preventDefault();
var Pagination_url = $(this).attr('href');
$.ajax({
url:Pagination_url,
type:'POST',
success:function(data){
var $page_data = $(data);
$('#container').html($page_data.find('div#body'));
$('#ul').addClass('ul');
}
});
});
});
</script>
型号:
public function management($limit, $start)
{
$this->db->limit($limit, $start);
$this->db->select('*');
$this->db->from('colleges');
$where = "field = 'management'";
$this->db->where($where);
$query = $this->db->get();
$result = $query->result_array();
return $result;
}
在这段代码中,我创建了一个ajax分页,我不想重新加载我的页面。我想在点击分页链接时显示没有刷新页面的数据,这就是我使用ajax分页的原因。在这里,我创建了ajax分页链接的分页显示但是当我点击该链接时,没有任何事情发生在页面保持相同。所以,我不知道我在哪里做错了可以帮我解决这个问题吗?请帮忙。
谢谢