溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

php中怎么利用ajax實現(xiàn)無刷新分頁

發(fā)布時間:2021-06-30 15:44:43 來源:億速云 閱讀:126 作者:Leah 欄目:web開發(fā)

本篇文章為大家展示了php中怎么利用ajax實現(xiàn)無刷新分頁,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。

<?php Header("Content-Type:text/html; charset=utf-8"); function AjaxPage($Total,$ListNub,$CurrentPage,$Url,$AjaxAction,$HalfPer='',$ViewId='') { //計算總頁數(shù) $totalPage = @ceil($Total/$ListNub); $total=$totalPage-1; $re=""; //echo $CurrentPage; $re .= ( $CurrentPage > 0 ) ?  "<td><a  href=\"javascript:$AjaxAction('$Url=0','$ViewId')\"\">首頁</a></td>\n<td><a  href=\"javascript:$AjaxAction('".$Url."=".($CurrentPage-1)."','$ViewId')\"\">上一頁</a></td>\n" :  "<td>首頁</td>\n<td>上一頁</td>\n"; for ( $i =  $CurrentPage - $HalfPer,$i > 0 || $i = 0 ,     $j =  $CurrentPage + $HalfPer, $j < $totalPage || $j = $totalPage;$i < $j ;$i++  ) {   $re .= $i == $CurrentPage   ?  "<td><b class=currentPage>[" . ( $i + 1 ) .  "]</b></td>\n"   : "<td><a  href=\"javascript:$AjaxAction('$Url=$i','$ViewId')\">" . ( $i + 1 ) .  "</a></td>\n"; } $re .= ( $CurrentPage < $total  ) ? "<td><a  href=\"javascript:$AjaxAction('".$Url."=".($CurrentPage+1)."','$ViewId')\"\">下一頁</a></td>\n<td><a  href=\"javascript:$AjaxAction('".$Url."=".($total)."','$ViewId')\"\">尾頁</a>\n</td>" :  "<td>下一頁</td>\n<td>尾頁</td>\n"; $re="<table  style=text-align:center><tr>$re</tr></table>"; return  $re; } //總頁數(shù),傳遞的頁面變量-當前頁 url地址 前后各多少頁 $page = $_GET['page']; //echo  page('10',$page,'index.php?page','2'); ?> <div id="nike"> <?php echo  AjaxPage(200,20,$page,'rand.php?page','ajaxaction','2','nike'); ?> </div> <script type="text/javascript" language="javascript"> var  http_request = false; function send_request(url,htmlid) { http_request =  false; if (window.XMLHttpRequest) {   http_request = new  XMLHttpRequest();   if (http_request.overrideMimeType)  {    http_request.overrideMimeType('text/xml');   } }  else if (window.ActiveXObject) {   try  {    http_request = new  ActiveXObject("Msxml2.XMLHTTP");   } catch (e)  {    try {     http_request = new  ActiveXObject("Microsoft.XMLHTTP");    } catch (e)  {}   } } if (!http_request)  {   alert('不能創(chuàng)建 XMLHttpRequest 對象!');   return  false; } http_request.onreadystatechange = function  (){likeakak(htmlid);}//processRequest(htmlid) http_request.open('GET',  url, true); http_request.send(null); } //處理返回信息 function processRequest(htmlid) { if  (http_request.readyState == 1)  {   document.getElementById(htmlid).innerHTML="下載中..."; } if  (http_request.readyState == 4) {   if (http_request.status == 200)  {    document.getElementById(htmlid).innerHTML=http_request.responseText;   }  else  {    alert('請求異常');   } } } //處理返回信息 function  likeakak(htmlid) { if (http_request.readyState == 1)  {   document.getElementById(htmlid).innerHTML="下載中..."; } if  (http_request.readyState == 4) {   if (http_request.status == 200)  {    document.getElementById(htmlid).innerHTML=http_request.responseText;   }  else  {    alert('請求異常');   } } } function  ajaxaction(url,viewid) { send_request(url,viewid); } //自定義調(diào)用函數(shù) function elist(id) { var inputarray = new  Array(); inputarray[1] = 'aaa'; inputarray[2] =  'bbb'; inputarray[3] = 'ccc'; inputarray[4] =  'ddd'; inputarray[5] = 'eee'; send_request('ajax.php?do=ajax&sort='+id,inputarray[id]); } </script>

上述內(nèi)容就是php中怎么利用ajax實現(xiàn)無刷新分頁,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注億速云行業(yè)資訊頻道。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI