Alternative AJAX paging Implementation Method for parsing CI

Source: Internet
Author: User

After reading the CI paging class, I did not write about AJAX. I also saw several other paging class extensions on the forum, which I think is not necessary.
On the basis of the existing, a small change can still be implemented.
Enter the subject below:
The native paging class of CI has a parameter $ config [anchor_class]
This parameter is used to set the pagination link style, so we can set it as follows:
$ Config [anchor_class] = "class = ajax_fpage ";
In the view section, disable the default action of the signature to obtain the AJAX effect.
The Code is as follows:
Copy codeThe Code is as follows: <script>
$ (. Ajax_fpage). click (function (e ){
Var url = $ (this). attr (href );
$. Get (url, {}, function (res ){
Certificate (+show_what_table).html (res );
});
Event. preventDefault ();
});
</Script>

When you click ajax_fpage, disable the default action of the tag and obtain the href information. Then, use the get method to obtain the href content and update the dom.

This completes ajax paging. Therefore, you do not need to extend the original class.
The detailed PHP code is as follows:
Copy codeThe 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] = ;
$ 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.