本篇文章為大家展示了使用Ajax怎么實(shí)現(xiàn)一個(gè)無刷新分頁,內(nèi)容簡明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。
新華網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián)公司,新華網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為新華成百上千提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)營銷網(wǎng)站建設(shè)要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的新華做網(wǎng)站的公司定做!
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Document</title> <script src="jquery-1.11.2.min.js"></script> <style type="text/css"> .dangqian{ background-color:#69F} </style> </head> <body> <div> <input type="text" id="key" /> <input type="button" value="查詢" id="chaxun" /> </div> <table width="50%" border="1" bordercolordark="0" bordercolorlight="0"> <tr> <td>代號(hào)</td> <td>名稱</td> <td>父級(jí)代號(hào)</td> </tr> <tbody id="neirong"><!--顯示內(nèi)容--> </tbody> </table> <div id="fenyexinxi"> </div> </body> <script type="text/javascript"> var page = 1;//定個(gè)變量,當(dāng)前要顯示的頁 Load();//加載數(shù)據(jù) Loadfenyexinxi();//加載分頁信息 //查詢 $("#chaxun").click(function(){ page = 1; Load();//加載數(shù)據(jù) Loadfenyexinxi();//加載分頁信息 }) function Load() { var key = $("#key").val();//查詢條件。用戶輸入的內(nèi)容 $.ajax({ url:"chuli.php", data: { page: page, key: key },//傳2個(gè)參數(shù)一當(dāng)前頁2關(guān)鍵字也就是查詢條件 type:"POST", dataType:"JSON", success: function(data){//匿名函數(shù) var str = "";//這個(gè)將來要放表格顯示的 for(var k in data)//通過K可以獲得每一條數(shù)據(jù) {//加載數(shù)據(jù)完成 str +="<tr><td>"+data[k].AreaCode+"</td><td>"+data[k].AreaName+"</td><td>"+data[k].ParentAreaCode+"</td></tr>";//要顯示的內(nèi)容,代號(hào)、名稱父級(jí)代號(hào) } $("#neirong").html(str); } }); } function Loadfenyexinxi()//分頁信息 { var str = ""; var minys = 1;//最小頁數(shù) var maxys = 1;//最大頁數(shù) var key = $("#key").val();//取關(guān)鍵字用于傳到zys頁面用 $.ajax({ async:false, type:"POST", url:"fenye.php", data:{key:key}, dataType:"TEXT", success:function(d){ maxys = d; } }); str += "<span style='text-decoration:underline; cursor:pointer'>總共:"+maxys+"頁</span> "; str += "<span id='prev' style='text-decoration:underline; cursor:pointer'>上一頁</span>"; for(var i=page-2;i<page+3;i++) { if(i>=minys && i<=maxys) { if(i==page) { str += "<span style='text-decoration:underline; cursor:pointer' class='dangqian' bs='"+i+"'>"+i+"</span> "; } else { str += "<span style='text-decoration:underline; cursor:pointer' class='list' bs='"+i+"'>"+i+"</span> "; } } } str += "<span style='text-decoration:underline; cursor:pointer' id='next'>下一頁</span>"; $("#fenyexinxi").html(str); $("#prev").click(function(){ page = page-1; if(page<1) { page=1; } Load(); Loadfenyexinxi(); }) $("#next").click(function(){ page = page+1; if(page>maxys) { page=maxys; } Load(); Loadfenyexinxi(); }) $(".list").click(function(){ page = parseInt($(this).attr("bs")); Load(); Loadfenyexinxi(); }) } </script> </html>
上面是這頁面:test.php
<?php include("DBDA.class.php"); $db = new DBDA(); //把上個(gè)頁面的2個(gè)值傳過來 $page = $_POST["page"];//當(dāng)前頁 $key = $_POST["key"];//條件,關(guān)鍵字 $num = 20;//定義,一頁里多少條數(shù)據(jù), $tiaoshu = ($page-1)*$num;//$tiaoshu跳過多少條($page-1)*$num現(xiàn)在$num是20條 //寫$SQL語句 $sql = "select * from chinastates where areaname like '%{$key}%' limit {$tiaoshu},{$num}";//根據(jù)關(guān)鍵字查like '%{$tiaojian}%'。 echo $db->JSONQuery($sql);
上面是處理頁面:chuli.php:
<?php include("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);
上述內(nèi)容就是使用Ajax怎么實(shí)現(xiàn)一個(gè)無刷新分頁,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
網(wǎng)站欄目:使用Ajax怎么實(shí)現(xiàn)一個(gè)無刷新分頁
轉(zhuǎn)載源于:http://aaarwkj.com/article36/peissg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)公司、網(wǎng)站設(shè)計(jì)、網(wǎng)站收錄、關(guān)鍵詞優(yōu)化、企業(yè)網(wǎng)站制作、網(wǎng)站營銷
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)