【问题标题】:CodeIgniter pagination with AjaxCodeIgniter 使用 Ajax 进行分页
【发布时间】: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


    【解决方案1】:

    请在视图中使用此代码

    $(function() {
         paginate();
     });
    
     function paginate() {
         $(document).on('click', '#ajax_pg a', function(event) {
             var url = $(this).attr('href');
             alert(url);
             return false;
         }).click(); //to trigger click event 
     }
    

    【讨论】:

      猜你喜欢
      • 2013-09-07
      • 1970-01-01
      • 1970-01-01
      • 2017-08-17
      • 1970-01-01
      • 1970-01-01
      • 2014-03-08
      • 2012-06-05
      相关资源
      最近更新 更多