分页链接在codeigniter中无法正常工作

时间:2018-01-01 09:50:16

标签: php jquery ajax codeigniter pagination

我正在使用ajax在codeigniter中进行分页,我有分页链接的问题,如果我点击第二个链接然后url会改变但第二页上没有数据加载,并且还显示第二个链接的活动第一个链接。< / p>

我的控制器功能来自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);
            }

    }

并通过ajax查看页面products.php编码getdata的发送输入

$(".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);

        }
        });

    });

这里是点击链接后获取数据的编码

$(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 个答案:

答案 0 :(得分:2)

将您的基本网址设置为您应用分页的网页的当前网址

if UIApplication.shared.canOpenURL(url) {
    if #available(iOS 10.0, *) {
         UIApplication.shared.open(url, options: [:], completionHandler: { (success) in

         })
    } else {
         UIApplication.shared.openURL(url)
    }
}

例如:$config["base_url"] = "#";

试试这个link例如