Simple implementation of jquery ajax paging plug-in and jqueryajax paging plug-in

Source: Internet
Author: User

Simple implementation of jquery ajax paging plug-in and jqueryajax paging plug-in

Speaking of jQuery-based ajax paging plug-ins, Let's first look at the main code structure:

1. First define a pager object:

Var sjPager = window. sjPager = {opts: {// default attribute pageSize: 10, preText: "pre", nextText: "next", firstText: "First", lastText: "Last", shiftingLeft: 3, shiftingRight: 3, preLeast: 2, nextLeast: 2, showFirst: true, showLast: true, url: "", type: "POST", dataType: "JSON ", searchParam :{}, beforeSend: null, success: null, complete: null, error: function () {alert ("sorry, request error. Please try again! ") ;},}, PagerElement: null, // page dom element commonHtmlText: {// public text variable}, init: function (obj, op) {// object initialization}, doPage: function (index, pageSize, searchParam) {// execution paging method}, getTotalPage: function () {// retrieve the total number of pages}, createPreAndFirstBtn: function (pageTextArr) {// create previous page and homepage button link}, createNextAndLastBtn: function (pageTextArr) {// create next page and last page button link}, createIndexBtn: function (pageTextArr) {// link to the center paging Index button}, renderHtml: function (pageTextArr) {// render the paging control to the page}, createSpan: function (text, className) {// create span}, createIndexText: function (index, text) {// create index text}, jumpToPage: function () {// jump }}

The object contains the paging attributes and the methods used. doPage () is the core paging method.

2. jQuery Extension

$.fn.sjAjaxPager = function (option) {    return sjPager.init($(this), option);  };

3. Plug-ins

 <body>     <table id="dataTable" border="1px"></table>  <div id="pager"></div> </body>
$ (Function () {$ ('# pager '). sjAjaxPager ({url: "Handler1.ashx", pageSize: 10, searchParam: {/** if there are other query conditions, you can directly input them here */id: 1, name: 'test',}, beforeSend: function () {}, success: function (data) {/** the returned data is processed as needed */var tableStr = "<tr> <td> Id </td> <td> name </td> <td> age </td> </tr> "; $. each (data. items, function (I, v) {tableStr + = "<tr> <td>" + v. id + "</td> <td>" + v. name + "</td> <td>" + v. age + "</td> </tr>" ;}); Parameters ('your datatable'your .html (tableStr) ;}, complete: function (){}});})

Have you found that the method of using ajax is basically the same as that of using ajax directly?

Finally, we can see the effect: (The table style is not set ugly, you can also modify the css file as needed)

F12 open the debugging tool and click the page to view the sent request and response:

  

  

PageIndex and pageSize are default parameters of the plug-in. They can be obtained directly in the Request in the background. Note that the response of the plug-in also follows the specific format {"total": 0, "items": []}. As shown in, total indicates the total number of data records, items indicates paging data.

Here, only the general structure of the Code and the effect of the Code are displayed. You may wish to implement it first.

Articles you may be interested in:
  • JQuery ajax paging plug-in instance code
  • Use JQuery to implement paging plug-in sharing
  • JQuery + Ajax implements no refreshing pages
  • Code of Baidu paging footprint simulation implemented by jQuery
  • Code for the pseudo-Paging effect implemented by jquery
  • Complete jQuery example code without refreshing pagination
  • Jquery plug-in pagination for refreshing ajax pages
  • JQuery + Ajax + PHP + Mysql: display data by PAGE
  • JQuery + Ajax for data query, sorting, and paging
  • Use JQUERY paging control in ANGULARJS
  • JQuery implements an animation paging instance with shuffling Effect
  • The tab bar effect implemented by jQuery + css

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.