Parse CI's alternative method for AJAX paging
- 2020-06-22 23:58:31
- OfStack
After looking at 1 page class of CI and not writing about AJAX, I also saw several other page class extensions written on the forum. I felt that it was not necessary.
It is possible to make one small change to the existing system.
Let's get down to business:
CI's native paging class has 1 parameter $config[anchor_class]
This parameter is used to style the paging link, so we can set it like this:
$config[anchor_class] = "class=ajax_fpage";
Then in view section, the default action of a note is prohibited to obtain AJAX's fetching effect.
The code is as follows:
When ajax_fpage clicks, disable the default action of the a tag and get href information, then use the get method to get href's content and update dom.
This completes a full ajax page. This eliminates the need to extend the original class.
The detailed PHP code is as follows:
It is possible to make one small change to the existing system.
Let's get down to business:
CI's native paging class has 1 parameter $config[anchor_class]
This parameter is used to style the paging link, so we can set it like this:
$config[anchor_class] = "class=ajax_fpage";
Then in view section, the default action of a note is prohibited to obtain AJAX's fetching effect.
The code is as follows:
<script>
$(.ajax_fpage).click(function(e){
var url = $(this).attr(href);
$.get(url,{},function(res){
$(#show_what_table).html(res);
});
event.preventDefault();
});
</script>
When ajax_fpage clicks, disable the default action of the a tag and get href information, then use the get method to get href's content and update dom.
This completes a full ajax page. This eliminates the 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] = <p>;
$config[full_tag_close] = </p>;
$config[display_pages] = FALSE;
$this->load->helper(url);
$skin_url = base_url().APPPATH . "views/templates";
$config[next_link] = <img src=".$skin_url./images/page_next.gif">;
$config[next_tag_open] = <li class="fr">;
$config[next_tag_close] = </li>;
$config[prev_link] = <img src=".$skin_url./images/page_prev.gif">;
$config[prev_tag_open] = <li class="fr">;
$config[prev_tag_close] = </li>;
$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);
}