Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize AJAX pagination in CI

Shulou Source: shulou.com Published: 2022-06-03 06:41:15 09月19日 Update

This article will explain in detail how to achieve AJAX paging in CI. Xiaobian thinks it is quite practical, so share it with you for reference. I hope you can gain something after reading this article.

Topic:

CI's native paging class has a parameter $config[anchor_class]

This parameter is used to set the style of pagination links, so we can set it like this:

$config[anchor_class] = "class=ajax_fpage";

Then in the view section, this method of prohibiting the default action of a note is used to obtain the AJAX call effect.

The code is as follows:

$(.ajax_fpage).click(function(e){

var url = $(this).attr(href);

$.get(url,{},function(res){

$(#show_what_table).html(res);

});

event.preventDefault();

});

When ajax_fpage is clicked, disable the default action of a tag, and get href information, then use the get method to get the content of href, and update dom.

A complete Ajax page is created. So there is no need to extend the original class.

The detailed PHP code is as follows:

function ContentList($id,$p=0)

{

$this->load->library(pagination);

$config[base_url] = site_url(qyadmin/ContentList/.$ id./.$ p);

$config[total_rows] = $this->admin->content_list($id,$p,1);

$config[per_page] = 5;

$config[uri_segment] = 5;

$config[first_link] = FALSE;

$config[last_link] = FALSE;

$config[full_tag_open] =

;

$config[full_tag_close] =

;

$config[display_pages] = FALSE;

$this->load->helper(url);

$skin_url = base_url().APPPATH . "views/templates";

$config[next_link] =

;

$config[next_tag_open] = ;

$config[next_tag_close] = ;

$config[prev_link] =

;

$config[prev_tag_open] = ;

$config[prev_tag_close] = ;

$config[anchor_class] = class="ajax_fpage";

$this->pagination->initialize($config);

$content = $this->admin->content_list($id,$p,0,$config[per_page],$this->uri->segment(5));

$fpage = $this->pagination->create_links();

$this->smarty->assign(fpage,$fpage);

$this->smarty->assign(content,$content);

$this->smarty->view(show.tpl);

}

About "CI how to achieve AJAX paging" this article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.

Tags: Articles code content actions parameters methods more good original practical notes information effects articles times tags styles topics knowledge parts Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Information Redmi Apple MySQL