Ajax分页不会更改活动链接

时间:2022-11-21 16:09:39

Hello I am going to make an ajax pagination using codeigniter.. I've tried the code but it seems pagination doesn't change the active link.. please help me.. here is my ajax

您好我将使用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;
  });
}

});

});

another ajax code I've tried

另一个我试过的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;
    });
});

my view pagination id

我认为分页ID

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

My controller

我的控制器

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

please help me

请帮帮我

1 个解决方案

#1


0  

a perfect ajax pagination for codeigniter, please refer the below link:

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

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

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

me using this, working fine....

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

here is the code that i used to display employee details:

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

--ajax controller--

--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 in page--

- 页面中的ajax脚本 -

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

u have to download the jquery_pagination library from:

你必须从以下网址下载jquery_pagination库:

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

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

and copy it to library folder in application folder in codeigniter.

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

before using u need to load the library using:

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

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

Thank you...

谢谢...

showAjax is a custom js function which used to display the desponse with some effect:

showAjax是一个自定义的js函数,用于显示具有一些效果的desponse:

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

#1


0  

a perfect ajax pagination for codeigniter, please refer the below link:

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

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

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

me using this, working fine....

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

here is the code that i used to display employee details:

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

--ajax controller--

--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 in page--

- 页面中的ajax脚本 -

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

u have to download the jquery_pagination library from:

你必须从以下网址下载jquery_pagination库:

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

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

and copy it to library folder in application folder in codeigniter.

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

before using u need to load the library using:

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

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

Thank you...

谢谢...

showAjax is a custom js function which used to display the desponse with some effect:

showAjax是一个自定义的js函数,用于显示具有一些效果的desponse:

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