Ajax implements data paging query and ajax implements data Paging

Source: Internet
Author: User
Tags zts

Ajax implements data paging query and ajax implements data Paging

Ajax is used to query databases and pagination of queried data for your reference. The specific content is as follows:

Homepage code

<Html xmlns = "http://www.w3.org/1999/xhtml"> 

Js Code

<Script type = "text/javascript"> var page = 1; // the current page defines the current page of a variable Load (); // Load the data LoadXinXi (); // load the page information // query $ ("# chaxun "). click (function () {page = 1; Load (); // Load data LoadXinXi (); // Load paging information}) function Load () {var key = $ ("# key "). val (); // query condition $. ajax ({url: "chuli. php ", data: {page: page, key: key}, type:" POST ", dataType:" JSON ", success: function (data) {var str = ""; for (var k in data) {str + = "<tr> <td>" + data [k]. areaCode + "</td> <td>" + data [k]. areaName + "</td> <td>" + data [k]. parentAreaCode + "</td> </tr>" ;}$ ("# nr" ).html (str); // return data to the table});} functionLoadXinXi () {var str = ""; var minys = 1; var maxys = 1; var key = $ ("# key "). val (); // query the total number of pages $. ajax ({async: false, url: "zys. php ", data: {key: key}, type:" POST ", dataType:" TEXT ", success: function (d) {maxys = d ;}}); str + = "<span> total:" + maxys + "page </span>"; str + = "<span id = 'prev'> previous page </span> "; for (var I = page-2; I <page + 3; I ++) {if (I> = minys & I <= maxys) {if (I = page) {str + = "<span class = 'hangzhou' bs = '" + I + "'>" + I + "</span> ";} else {str + = "<span class = 'LIST' bs = '" + I + "'>" + I + "</span> ";}}} str + = "<span id = 'Next'> next page </span>"; $ ("# xinxi" ).html (str ); // Add a click event to the previous page $ ("# prev "). click (function () {page = page-1; if (page <1) {page = 1;} Load (); // Load data LoadXinXi (); // load page information}) // Add a click event to the next page $ ("# next "). click (function () {page = page + 1; if (page> maxys) {page = maxys;} Load (); // Load data LoadXinXi (); // load paging information}) // Add an event to the intermediate list $ (". list "). click (function () {page = parseInt ($ (this ). attr ("bs"); Load (); // Load data LoadXinXi (); // Load paging information})} </script>

Processing page 1

<?phpinclude("DBDA.class.php");$db = new DBDA();$key = $_POST["key"];$num = 20;$sql = "select count(*) from chinastates where areaname like '%{$key}%'";$zts = $db->StrQuery($sql);echo ceil($zts/$num);

Processing page 2

<?phpinclude("DBDA.class.php");$db = new DBDA();$page = $_POST["page"];$key = $_POST["key"];$num = 20;$tiao = ($page-1)*$num;$sql = "select * from chinastates where areaname like '%{$key}%' limit {$tiao},{$num}";echo $db->JSONQuery($sql);

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.