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

报告相同问题?

悬赏问题

  • ¥15 防火墙的混合模式配置
  • ¥15 Ubuntu不小心注销了要怎么恢复啊
  • ¥15 win10电脑安装完plcsim advanced4.0运行时为什么会提示找不到虚拟网卡
  • ¥15 安装powerbuilder10卡在安装程序正在运行这个页面 没有下一步任何指令
  • ¥15 关于mpi的问题:请问遇到这种情况需要怎么解决,出现这个问题后电脑不能进行mpi多核运行只能进行单核运行
  • ¥50 微信聊天记录备份到电脑提示成功了,但还是没同步到电脑微信
  • ¥15 python怎么在已有视频文件后添加新帧
  • ¥20 虚幻UE引擎如何让多个同一个蓝图的NPC执行一样的动画,
  • ¥15 fluent里模拟降膜反应的UDF编写
  • ¥15 MYSQL 多表拼接link