php ajax无刷新分页 支持id定位的代码分享
发布:smiling 来源: PHP粉丝网 添加日期:2018-11-07 11:52:31 浏览: 评论:0
- <?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');
- ?>
- <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';
- //phpfensi.com
- send_request('ajax.php?do=ajax&sort='+id,inputarray[id]);
- }
- </script>
Tags: php ajax 无刷新分页
相关文章
- ·php分页代码与分页原理(2013-11-12)
- ·PHP分页显示制作(2013-11-13)
- ·PHP实现翻页跳转功能(2013-11-13)
- ·自定义PHP分页函数(2013-11-13)
- ·小谈PHP&MYSQL分页原理及实现(2013-11-13)
- ·php中分页显示文章标题(2013-12-10)
- ·PHP MySQL分页显示(2013-12-10)
- ·一款php分页代码(2013-12-16)
- ·php分页代码(2013-12-16)
- ·PHP+AJAX无刷新分页实现代码详解(2014-01-03)
- ·PHP 分页代码与分页原理解析(2014-01-06)
- ·php文章内容分页实例程序(2014-01-07)
- ·php中分页程序之基于留言板详解(2014-01-15)
- ·php分页可利用表格来分页类(2014-01-15)
- ·简单入门级php分页代码(2014-05-10)
- ·PHP简单分页函数代码总结(2014-06-18)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)