I am working on pagination in codeigniter using ajax , I have problem with pagination links, if I click on second link then url will change but there is no data load on second page and also showing active first link with second link.
我正在使用ajax在codeigniter中进行分页,我对分页链接有问题,如果我点击第二个链接,那么url将会改变,但是在第二个页面上没有数据加载,并且显示活动的第一个链接和第二个链接。
my controller function from star.php
我的控制器函数
public function filtersearch()
{
$proSearch = implode(",", $_POST['search']) ;
$cat = $_POST['cat'];
log_message('error', 'post value is '.$proSearch );
log_message('error', ' '.$cat );
$config = array();
$config["base_url"] = "#";
$config['page_query_string'] = TRUE;
$config['reuse_query_string'] = true;
$config["total_rows"] = $this->Star_model->getfilterCount($proSearch,$cat);
$config["per_page"] = 2;
$config["uri_segment"] = 4;
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = false;
$config['last_link'] = false;
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '«';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '»';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
$offset = $this->input->get('offset');
$this->pagination->cur_page = $offset;
$data['links'] = $this->pagination->create_links();
$output = array(
'pagination_link' => $this->pagination->create_links(),
'country_table' => $this->Star_model->getfilterSearch($proSearch,$cat,$config["per_page"],$offset)
);
$this->output->set_content_type('application/json');
echo json_encode($output);
}
}
and view page products.php coding for send input for getdata through ajax
并查看页面的产品。通过ajax发送getdata输入的php编码
$(".cl").live("click", function () {
var val = $('input[type=checkbox]:checked').map(function(_, el) {
return $(el).val();
}).get();
var cat = $("#sub_cat").val();
$.ajax({
type: "POST",
url: "<?php echo base_url();?>star/filtersearch",
data: {search: val, cat: cat},
dataType:"json",
success:function(data){
$("#asd").hide();
$('#country_table').html(data.country_table);
$('#pagination_link').html(data.pagination_link);
}
});
});
here is coding of getting data after click on link
这里是点击链接后获取数据的编码
$(document).ready(function(){
function load_data(page)
{
var val = $('input[type=checkbox]:checked').map(function(_, el) {
return $(el).val();
}).get();
var cat = $("#sub_cat").val();
alert(val+cat);
$.ajax({
url:"<?php echo base_url();?>star/filtersearch",
method:"POST",
data: {search: val, cat: cat},
dataType:"json",
success:function(data)
{
$('#country_table').html(data.country_table);
$('#pagination_link').html(data.pagination_link);
$("#asd").hide();
}
});
}
load_data(1);
$(".pagination li a").live("click", function () {
var cur_page = $(this).attr('data-ci-pagination-page'); // I haved test with attr('href') but not ok.
load_data(cur_page);
});
});
1 个解决方案
#1
2
set your base url as the current URL of the page where you are applying the pagination
将基本url设置为正在应用分页的页面的当前url。
$config["base_url"] = "#";
eg: $config["base_url"] = base_url() . 'user/index';
$config["base_url"] = base_url()。“用户/指数”;
Try This link for example
例如,试试这个链接
#1
2
set your base url as the current URL of the page where you are applying the pagination
将基本url设置为正在应用分页的页面的当前url。
$config["base_url"] = "#";
eg: $config["base_url"] = base_url() . 'user/index';
$config["base_url"] = base_url()。“用户/指数”;
Try This link for example
例如,试试这个链接