Paging with Ajax

Source: Internet
Author: User

Front page:

                    <table class= "Table Table-hover" > <thead> < tr> <th class= ' hidden-xs ' > code name </th> <th> Username </th&gt                          ;                          <th class= ' hidden-xs ' > Product code </th> <th class= ' hidden-xs ' > Watch type </th>                        <th class= ' Hidden-xs ' > Audit status </th> <th> actions </th>                                             </tr> </thead> <tbody id= "ZY_BG" >                    </tbody> </table> <!--end of table-                     <!--paging Start-<center> <ul class= "pagination" id= "fy_list" >            </ul> <input type= "hidden" value= "1" id= "Fy_n"/>//the number of pages displayed        </center> <!--pagination--</div> &LT;/DIV&G                T </div> </div> </div></div><!--content End--><script type= "Text/javascript" > $ ( Document). Ready (function (e) {//Get paging Jiazai (); var Zys = 0;//Set the initial total number of pages for the 0//page load data function Jiazai ()//do a load method {var n = $ ("#fy_n           "). Val (); $.ajax ({url: "chuli/chakan.php", Data:{n:n},type: "POST", DataType: "JSON", success:function (data) {var str = ""; for (var I in data) {str = str+ "<tr><th>" +data[i].code+ "</th><th>" +data[i].bname+ "</th><th > "+data[i].pdcode+" </th><th> "+data[i].lxcode+" </th><th> "+data[i].auditing+" </th ><th> delete </th></tr> ";}    $ ("#zy_bg"). html (str);  }  }); Gets the number of pages (list) $.ajax ({url: "chuli/zyxchuli.php", DataType: "TEXT", success:function (data) {//total pages var ys = Math.ceil (DATA/6 )///Up page Zys = Ys;var s = "<li><a id= ' Fy_shang ' > previous </a></lI> "; var Dangqian = $ (" #fy_n "). Val (); Current page for (Var i=dangqian-2;i<=dangqian+2;i++)//display five pages {if (i>0 && i<=ys) {if (dangqian==i) {s+= "< Li class= ' active ' ><a class= ' fy_zhong ' > ' +i+ ' </a></li> ';} else{s+= "<li><a class= ' Fy_zhong ' >" +i+ "</a></li>"}}}s + = "<li><a id= ' Fy_xia ' >                   Next page </a></li> "; $ (" #fy_list "). HTML (s); Add Event Jiashijian () to the paging list;}) }//adds an event method function Jiashijian () {$ ("#fy_shang") to the paging list. Click (function () {var n = $ ("#fy_n"). Val (); if (n>1) {n--;} Else{n=1;} $ ("#fy_n"). Val (n);//Load Data Jiazai ();}) $ ("#fy_xia"). Click (function () {var n = $ ("#fy_n"). Val (); if (N<zys) {n++;} Else{n=zys;} $ ("#fy_n"). Val (n);//Load Data Jiazai ();}) $ (". Fy_zhong"). Click (function () {//click Pages to jump to the current page
var n = $ (this). text (); $ ("#fy_n"). Val (n);//Load Data Jiazai ();})} });</script>

  the background processing page needs to refer to a wrapper query method, the Background processing page (chakan.php):

<?phpsession_start (); Include ("..  /dbda.class.php "); $db = new Dbda (); $uid = $_session[" UID "]; $n = $_post[" n "];//echo $n; $TG = ($n-1) *6; $sql =" SELECT * FROM Buy where bname= ' {$uid} '  limit {$tg},6 ';//query data about user name, limit {$TG},6 is skip n data 6 data
Echo Json_encode ($db->guanquery ($sql), 1);

  Background Processing page (zyxchuli.php):

<?phpsession_start (); $uid = $_session["UID"];include (".. /dbda.class.php "); $db = new Dbda (); $sqlsj =" SELECT count (*) from buy where bname= ' {$uid} ' ";//Query The total number of data about the user name echo $db->s Trquery ($SQLSJ, 1);

  

Paging with Ajax

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.