php ajax無重新整理分頁,支援id定位範例程式碼

來源:互聯網
上載者:User
AJAX 是一種與伺服器交換資料的技術,可以在不重新載入整個頁面的情況下更新網頁的一部分。本文章主要介紹php 使用ajax實現的無重新整理分頁代碼

<?php Header("Content-Type:text/html; charset=utf-8"); function AjaxPage($Total,$ListNub,$CurrentPage,$Url,$AjaxAction,$HalfPer='',$ViewId='') { //計算總頁數 $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; } //總頁數,傳遞的頁面變數-當前頁 url地址 前後各多少頁 $page = $_GET['page']; //echo  page('10',$page,'index.php?page','2'); ?> <p id="nike"> <?php echo  AjaxPage(200,20,$page,'rand.php?page','ajaxaction','2','nike'); ?> </p> <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('不能建立 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); } //自訂調用函數 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>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.