Home > Backend Development > PHP Tutorial > PHP ajax no refresh paging, supports id positioning sample code

PHP ajax no refresh paging, supports id positioning sample code

怪我咯
Release: 2023-03-13 18:52:01
Original
1236 people have browsed it

AJAX is a technology for exchanging data with a server to update part of a web page without reloading the entire page. This article mainly introduces the refresh-free implementation of php using ajaxPaging code

<?php 
Header("Content-Type:text/html; charset=utf-8"); 

function AjaxPage($Total,$ListNub,$CurrentPage,$Url,$AjaxAction,$HalfPer=&#39;&#39;,$ViewId=&#39;&#39;) 
{ 
//计算总页数 
$totalPage = @ceil($Total/$ListNub); 
$total=$totalPage-1; 
$re=""; 
//echo $CurrentPage; 
$re .= ( $CurrentPage > 0 ) 
?  
"<td><a  
href=\"javascript:$AjaxAction(&#39;$Url=0&#39;,&#39;$ViewId&#39;)\"\">首页</a></td>\n<td><a  
href=\"javascript:$AjaxAction(&#39;".$Url."=".($CurrentPage-1)."&#39;,&#39;$ViewId&#39;)\"\">上一页</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(&#39;$Url=$i&#39;,&#39;$ViewId&#39;)\">" . ( $i + 1 ) .  
"</a></td>\n"; 
} 
$re .= ( $CurrentPage < $total  
) 
? "<td><a  
href=\"javascript:$AjaxAction(&#39;".$Url."=".($CurrentPage+1)."&#39;,&#39;$ViewId&#39;)\"\">下一页</a></td>\n<td><a  
href=\"javascript:$AjaxAction(&#39;".$Url."=".($total)."&#39;,&#39;$ViewId&#39;)\"\">尾页</a>\n</td>" 
:  
"<td>下一页</td>\n<td>尾页</td>\n"; 
$re="<table  
style=text-align:center><tr>$re</tr></table>"; 
return  
$re; 

} 
//总页数,传递的页面变量-当前页 url地址 前后各多少页 
$page = $_GET[&#39;page&#39;]; 
//echo  
page(&#39;10&#39;,$page,&#39;index.php?page&#39;,&#39;2&#39;); 


?> 

<p id="nike"> 
<?php 
echo  
AjaxPage(200,20,$page,&#39;rand.php?page&#39;,&#39;ajaxaction&#39;,&#39;2&#39;,&#39;nike&#39;); 
?> 
</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(&#39;text/xml&#39;); 
  } 
}  
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(&#39;不能创建 XMLHttpRequest 对象!&#39;); 
  return  
false; 
} 
http_request.onreadystatechange = function  
(){likeakak(htmlid);}//processRequest(htmlid) 
http_request.open(&#39;GET&#39;,  
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(&#39;请求异常&#39;); 
  } 
} 
} 
//处理返回信息 
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(&#39;请求异常&#39;); 
  } 
} 
} 
function  
ajaxaction(url,viewid) 
{ 
send_request(url,viewid); 
} 

//自定义调用函数 
function elist(id) 
{ 
var inputarray = new  
Array(); 

inputarray[1] = &#39;aaa&#39;; 
inputarray[2] =  
&#39;bbb&#39;; 
inputarray[3] = &#39;ccc&#39;; 
inputarray[4] =  
&#39;ddd&#39;; 
inputarray[5] = &#39;eee&#39;; 

send_request(&#39;ajax.php?do=ajax&sort=&#39;+id,inputarray[id]); 

} 

</script>
Copy after login

The above is the detailed content of PHP ajax no refresh paging, supports id positioning sample code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template