dongyao1895 2016-02-09 11:14
浏览 43
已采纳

CodeIgniter与Ajax分页

I want to include pagination in my site operated by AJAX.

MY CONTROLLER

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);
}

MY VIEW

$(function() {
    paginate();

    function paginate() {
        $('#ajax_pg a').on('click', function() {
            var url = $(this).attr('href');
            alert(url);

            return false;
        });
    }
});

Now the CI pagination is working all right but somehow or the other the ajax jQuery click event i not firing.

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dra87370 2016-02-09 11:58
    关注

    Please Use this code in view

    $(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 
     }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
  • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
  • ¥15 win10,这种情况怎么办
  • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
  • ¥100 在连接内网VPN时,如何同时保持互联网连接
  • ¥15 MATLAB中使用parfor,矩阵Removal的有效索引在parfor循环中受限制
  • ¥20 Win 10 LTSC 1809版本如何无损提升到20H1版本
  • ¥50 win10 LTSC 虚拟键盘不弹出
  • ¥30 微信小程序请求失败,网页能正常带锁访问
  • ¥15 Matlab求解微分方程,如何用fish2d进行预优?