Analysis CI's Ajax Paging alternative implementation method _php skills

Source: Internet
Author: User
Tags php code
Looked at the CI page class did not write about Ajax content, but also saw several other great God wrote the page class extension, it is not really necessary.
Making a small change on the existing basis is still achievable.
Let's get down to business:
CI's original Zoning page class has a parameter $config [Anchor_class]
This parameter is used to set the style of the pagination link, so we can set it like this:
$config [Anchor_class] = "Class=ajax_fpage";
Then, in the View section, we use the method of prohibiting the default action of a pad to obtain the effect of Ajax.
The code is as follows:
Copy Code code 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, the default action of a label is banned, the href information is obtained, and the Get method is used to get the content of the HREF and update the DOM.

Such a complete Ajax paging is achieved. This does not require an extension of the original class.
detailed PHP code is as follows:
Copy Code code 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] = ;
$config [Next_tag_open] = <li class= "FR" >;
$config [Next_tag_close] = </li>;
$config [Prev_link] = ;
$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);
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.