【问题标题】:Passing more parameters in Ajax_pagination in CodeIgniter 3.0在 CodeIgniter 3.0 的 Ajax_pagination 中传递更多参数
【发布时间】:2015-10-08 08:08:06
【问题描述】:

我在 CodeIgniter 3.0 中使用Ajax_pagination 库。分页工作正常。现在我想通过页面本身传递更多参数。

例如,我有一个用户选择国家和类别的页面。现在我想用分页显示数据。这是我的代码。

function ajaxPaginationData()
  {
 $page = $this->input->post('page');
    if(!$page){
        $offset = 0;
    }else{
        $offset = $page;
    }
    $totalRec = count($this->post->getRows());

    //pagination configuration
    $config['first_link']  = 'First';
    $config['div']         = 'postList'; //parent div tag id
    $config['base_url']    = base_url().'index.php/posts/ajaxPaginationData';
    $config['total_rows']  = $totalRec;
    $config['per_page']    = $this->perPage;
    $this->ajax_pagination->initialize($config);
    $data['posts'] = $this->post->getRows(array('start'=>$offset,'limit'=>$this->perPage));
   $this->load->view('posts/ajax-pagination-data', $data, false);
}

这是我的分页html

<div class="pagination">Showing 1 to 5 of 8 | &nbsp;<b>1</b>&nbsp;<a onclick="$.post('http://localhost:8080/ajax/index.php/posts/ajaxPaginationData/5', {'page' : 5}, function(data){
                $('#postList').html(data); }); return false;" href="javascript:void(0);">2</a>&nbsp;<a onclick="$.post('http://localhost:8080/ajax/index.php/posts/ajaxPaginationData/5', {'page' : 5}, function(data){
                $('#postList').html(data); }); return false;" href="javascript:void(0);">&gt;</a>&nbsp;</div>

现在在更改国家/地区下拉列表时,我想获取具有该 ID 的列表

<select id="country">
<option value="0">select</option>
<option value="1">USA</option>
<option value="2">UK</option>
</select>

【问题讨论】:

    标签: ajax codeigniter pagination


    【解决方案1】:

    在函数中传递下拉列表的值

    function ajaxPaginationData($country)
      {
     $page = $this->input->post('page');
        if(!$page){
            $offset = 0;
        }else{
            $offset = $page;
        }
        $totalRec = count($this->post->getRows());
    
        //pagination configuration
        $config['first_link']  = 'First';
        $config['div']         = 'postList'; //parent div tag id
        $config['base_url']    = base_url().'index.php/posts/ajaxPaginationData';
        $config['total_rows']  = $totalRec;
        $config['per_page']    = $this->perPage;
        $this->ajax_pagination->initialize($config);
        $data['posts'] = $this->post->getRows(array('start'=>$offset,'limit'=>$this->perPage));
       $this->load->view('posts/ajax-pagination-data', $data, false);
    }
    

    并使用 $country 从带有 where 条件的表中选择数据。

    有关分页的更多信息,请尝试http://w3code.in/2015/10/how-to-do-pagination-in-codeigniter/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-07
      • 2020-12-27
      • 2016-06-16
      • 2014-09-27
      • 1970-01-01
      • 1970-01-01
      • 2018-01-20
      相关资源
      最近更新 更多