Ajax分页不会更改活动链接

时间:2014-01-07 12:27:05

标签: php jquery ajax codeigniter pagination

您好我将使用codeigniter进行ajax分页。 我已经尝试过代码,但似乎分页不会改变活动链接.. 请帮我..  这是我的ajax

    $(function() {
applyPagination();
function applyPagination() {
  $("#paging a").click(function() {
    var url = $(this).attr("href");
    $.ajax({
      type: "POST",
      data: "ajax=1",
      url: url,
      beforeSend: function() {
        $("#things").html("");
      },
      success: function(msg) {
        $("#things").html(msg);
        applyPagination();
      }
    });
    return false;
  });
}

});

我试过的另一个ajax代码

<script>
$(document).ready(function(){
    $("#paging a").click(function()
    {
        var this_url = $(this).attr("href");

        $.post(this_url,{ },function(data){
            $("div#things").html(data);
        });
        return false;
    });
});

我的观点分页ID

<div class="paging" id="paging">
<aside>
<?php echo $links; ?>
</aside>
</div>

我的控制器

public function index($start_row="")
{
    /*Pagination*/
    $start_row = $this->uri->segment(4);

    $per_page=5;
    if(trim($start_row) == '')
    {
        $start_row = 0;
    }

    $result = $this->abouthistory_model->history_list();
    $data["CatId"]=$this->viewbook_model->getCategory();
    $total_rows=count($result);
    $this->load->library('pagination');

    $config['uri_segment'] = 4;
    $config['base_url'] = base_url()."about/abouthistory/index";
    $config['total_rows'] = $total_rows;
    $config['per_page'] =$per_page; 
    $config['is_ajax_paging']  =  TRUE; // default FALSE
    $config['paging_function'] = 'ajax_paging'; // Your jQuery paging

    $this->pagination->initialize($config); 
    $resultLimited =  $this->abouthistory_model->history_listLimited($start_row,$per_page);
    $data["CatId"]=$this->viewbook_model->getCategory();
    $data["links"]=$this->pagination->create_links();

请帮帮我

1 个答案:

答案 0 :(得分:0)

对于codeigniter的完美ajax分页,请参考以下链接:

http://tohin.wordpress.com/2008/08/12/codeigniter-ajax-pagination/

我用这个,工作得很好....

这是我用来显示员工详细信息的代码:

- ajax控制器 -

public function employeeListAjax()
{
    if (!$this->input->is_ajax_request())
    {
        redirect(site_url(), 'refresh');
    }
    $config['anchor_class'] = '';
    $config['show_count'] = true;
    $config['div'] = '#emp_list'; // div for displaying ajax
    $config['base_url'] = site_url('employee/employeeListAjax');
    $config['total_rows'] = sizeof($this->emp->empdetail());
    $config['per_page'] = 10;
    $this->jquery_pagination->initialize($config);
    $data['links'] = $this->jquery_pagination->create_links();
    $data['page'] = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
    $data['empdet'] = $this->emp->empdetail($config['per_page'], $data['page']);
    $this->load->view('modules/employee/ajax_emp_list', $data);
}

- 页面中的ajax脚本 -

<script>
    jQuery(function($){
        $.post("<?php echo site_url('employee/employeeListAjax');?>",
        {
        },
        function(response)
        {
        setTimeout("showAjax('#emp_list', '"+escape(response)+"')", 100);
        });
    });
</script>

你必须从:

下载jquery_pagination库

https://github.com/neotohin/CodeIgniter-Ajax-pagination-Library/blob/master/Jquery_pagination.php

并将其复制到codeigniter中的应用程序文件夹中的库文件夹。

使用之前你需要使用以下方法加载库:

$this->load->library('Jquery_Pagination');

谢谢...

showAjax 是一个自定义js函数,用于显示有一定影响的响应:

<script>
    function showAjax(id, response)
    {
    jQuery(id).hide();
    jQuery(id).html(unescape(response));
    jQuery(id).fadeIn(200);
    }
</script>
相关问题