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.