程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> PHP綜合 >> ajax無刷新分頁,支持id定位

ajax無刷新分頁,支持id定位

編輯:PHP綜合

<?PHP
Header("Content-Type:text/Html; charset=utf-8");
// AK QQ:42220796
// 總數 單頁條數 當前頁 點擊後的url地址get 應用的JS函數  顯示幾個  顯示的地址
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');


?>

<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('不能創建 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>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved