Ajax asynchronous paging request example using bootstrap-paginator.js paging, bootstrap paging example

Source: Internet
Author: User

Ajax asynchronous paging request example using bootstrap-paginator.js paging, bootstrap paging example

Ajax asynchronous paging requests using bootstrap-paginator.js pagination

The procedure is as follows:

First, define an ajax function for asynchronous request submission. The complete function is as follows:

Var nid = $ ("# lbnid "). val (); // obtain the current news number var cpage = 1; // the current page number var tpage = 10; // the total number of pages function getPaging () {getComment (cpage ); // get news comments} // click to view news comments $ ("# one2 "). click (function () {getPaging () ;}); // obtain the News Comment function getComment (page) {$. ajax ({type: "get", data: nid, async: "false", url: "/comment/GetComment? Nid = "+ nid +" & page = "+ page, success: function (info) {changeModel (info ); // update the local page var totalpage =$ ("# totalpage "). val (); // the current page number var curtpage = $ ("# curtpage "). val (); // total page number if (curtpage & totalpage) {cpage = curtpage; tpage = totalpage;} display (cpage, tpage); // display comments }, error: function () {alert ("loading failed! Please try again later! ") ;}}) ;}/ * Obj: html data returned by ajax * // update the function changeModel (obj) {var comt =$ (". comments "); comt. replaceWith ("<div class = Comments>" + obj + "</div>");}/* curreentpage: Current page number; tpage: total page count * // display News Comment function display (curtpage, tpage) {var options = {bootstrapMajorVersion: 3, // version currentPage: curtpage, // the current page number numberOfPages: 10, // set the number of displayed pages totalPages: tpage, // total number of pages itemTexts: function (type, page, current) {switch (type) {case "first ": return "Homepage"; case "prev": return "Previous page"; case "next": return "next page"; case "last": return "last page"; case "page ": return page ;}},}$ ("# page "). bootstrapPaginator (options );}

Next is to modify the original bootstrap-paginator.js file, this is also the most critical step

OnPageClicked: function (event, originalEvent, type, page) {// show the corresponding page and retrieve the newly built item related to the page clicked before for the event return var currentTarget = $ (event. currentTarget); switch (type) {case "first": currentTarget. bootstrapPaginator ("showFirst"); getComment (page); // custom method for getting news comments. Remember to add this custom function break; case "prev ": currentTarget. bootstrapPaginator ("showPrevious"); getComment (page); break; case "next": currentTarget. bootstrapPaginator ("showNext"); getComment (page); break; case "last": currentTarget. bootstrapPaginator ("showLast"); getComment (page); break; case "page": currentTarget. bootstrapPaginator ("show", page); getComment (page); break ;}},

Then OK. Run the following command:

 

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

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.