php ajax無刷新分頁,支持id定位
<?php
Header("Content-Type:text/html; charset=utf-8");
function AjaxPage($Total,$ListNub,$CurrentPage,$Url,$AjaxAction,$HalfPer='',$ViewId='')
{
//計(jì)算總頁數(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ù),傳遞的頁面變量-當(dāng)前頁 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 對(duì)象!');
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('請(qǐng)求異常');
}
}
}
//處理返回信息
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('請(qǐng)求異常');
}
}
}
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>
- php+ajax實(shí)現(xiàn)無刷新動(dòng)態(tài)加載數(shù)據(jù)技術(shù)
- php+html5實(shí)現(xiàn)無刷新圖片上傳教程
- PHP+ajax 無刷新刪除數(shù)據(jù)
- php+ajax實(shí)現(xiàn)無刷新分頁的方法
- AJAX PHP無刷新form表單提交的簡(jiǎn)單實(shí)現(xiàn)(推薦)
- PHP+AJAX實(shí)現(xiàn)無刷新注冊(cè)(帶用戶名實(shí)時(shí)檢測(cè))
- PHP Ajax實(shí)現(xiàn)頁面無刷新發(fā)表評(píng)論
- PHP Ajax實(shí)現(xiàn)頁面無刷新發(fā)表評(píng)論
- ajax實(shí)現(xiàn)無刷新分頁(php)
- PHP+Ajax無刷新帶進(jìn)度條圖片上傳示例
- php的無刷新操作實(shí)現(xiàn)方法分析
相關(guān)文章
基于Ajax技術(shù)實(shí)現(xiàn)考試倒計(jì)時(shí)并自動(dòng)提交試卷
這篇文章主要介紹了基于Ajax技術(shù)實(shí)現(xiàn)考試倒計(jì)時(shí)并自動(dòng)提交試卷 的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-06-06解決ajax回調(diào)函數(shù)返回的字符串亂碼問題
ajax回調(diào)函數(shù),返回的字符串亂碼問題很是讓人痛恨,下面有個(gè)不錯(cuò)的解決方法,大家可以參考下2014-01-01Ajax 設(shè)置Access-Control-Allow-Origin實(shí)現(xiàn)跨域訪問
這篇文章主要介紹了Ajax 設(shè)置Access-Control-Allow-Origin實(shí)現(xiàn)跨域訪問,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-02-02AJAX和三層架構(gòu)實(shí)現(xiàn)分頁功能具體思路及代碼
本文涉及到AJAX和三層架構(gòu)方面的知識(shí),在學(xué)習(xí)分頁的同時(shí)也鞏固了一下它們的相關(guān)知識(shí),適合初學(xué)者的你2013-05-05