ajax完美实现两个网页 分页功能的实例代码
2015-01-24信息快讯网
ajax完美实现两个网页 分页功能的实例代码,需要的朋友可以参考一下
分页的首页
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<h1 align="center">武侠小说分页</h>
<br/>
<script src="jquery-1.4.2.min.js"></script>
<script>
var page='';
function init(page){
document.getElementById("tables").innerHTML='';
var xhr;
if(window.XMLHttpRequest){
xhr = new XMLHttpRequest();
}else if(window.ActiveXObject){
xhr =new ActiveXObject("Microsoft.XMLHTTP")
}
var url="fenye.php";
xhr.open("POST",url,true);
xhr.onreadystatechange=callback;
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
if(page){
xhr.send("page="+page);
}
else {xhr.send("page=1");}
var content;
function callback(){
if(xhr.readyState==4){
if(xhr.status==200){
var json =eval('('+xhr.responseText+')');
//alert(xhr.responseText);
var fenye=json.str;
// alert(fenye);
document.getElementById('div').innerHTML=fenye;
content="<th>ID</th><th>名称</th><th>作者</th><th>出版社</th><th>ISBN号</th><th>类型</th><th>价格</th>";
for(var i=0;i<json.info.length;i++){
content+="<tr><td>"+json.info[i].id+"</td><td>"+json.info[i].name+"</td><td>"+json.info[i].author+"</td><td>"+json.info[i].publisher+"</td><td>"+json.info[i].isbn+"</td><td>"+json.info[i].type+"</td><td>"+json.info[i].price+"</tr>";
document.getElementById("tables").innerHTML=content;
}
// alert(fenye);
}
}
}
}
</script>
<body onLoad="init()">
<h3 align="center">jquery实现$.ajax的分页</h3>
<table id="tables" style=" width:500px; height:100px; text-align:center" align="center" border="5" bordercolor="#FF6600">
<th>ID</th><th>名称</th><th>作者</th><th>出版社</th><th>ISBN号</th><th>类型</th><th>价格</th>
</table>
<table align="center" style="margin-top:15px">
<tr><td>
<td style="colspan:3;height:20">
<div id="div" style="position:absolute; left: 447px; top: 218px; width: 411px; height: 22px;"></div>
</td>
</tr>
</table>
<br />
</body>
分页的php精华代码
<?php
//命令模型层处理数据
$link=mysql_connect('localhost','root','') or die("失败");
mysql_select_db('books',$link) or die("连接数据库出错了!");
//每页显示记录数
$pagesize = 2;
//求出总的记录数
$sql = "select count(*) as total_rows from books";
$result = mysql_query($sql);
$total_rows = mysql_fetch_array($result);
//求总共的页码数
$pages = ceil($total_rows[0]/$pagesize);
//当前第几页
$page = $_POST['page'];
$strtext = "当前第".$page."页"."总共".$pages."页"."共".$total_rows[0]."记录";
//var_dump($str);
//接下来,我要根据当前点击的页码求出对应的数据
$offset = $pagesize*($page-1);
$sql = "select * from books limit $offset,$pagesize";
mysql_query("set names utf8");
$res=mysql_query($sql);
$rows=array();
while($row=mysql_fetch_assoc($res)){
$rows[]=$row;
}
$pageInfo = $rows;
//echo json_encode($pageInfo);
//var_dump($pageInfo);
//将获得数据链接,后返回
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pages;
//命令视图层显示数据
$first_a = "<a onclick='init(".$first.")' href='#'><img src='3.jpg' width='50px;' height='20px;'/></a>";
if($page>1){
$prev_a = "<a onclick='init(".$prev.")' href='#'><img src='1.jpg' width='50px;' height='20px;'/></a>";
}
if($page<$pages){
$next_a = "<a onclick='init(".$next.")' href='#'><img src='2.jpg' width='50px;' height='20px;'/></a>";
}
$last_a = "<a onclick='init(".$last.")' href='#'><img src='4.jpg' width='50px;' height='20px;'/></a>";
@$str = $strtext.$first_a.$prev_a.$next_a.$last_a;
//var_dump($str);
$info = array('str'=>$str,'info'=>$pageInfo);
echo json_encode($info);
显示程序执行时间php函数代码
php+js实现图片的上传、裁剪、预览、提交示例
php实现利用phpexcel导出数据
PHP实现读取一个1G的文件大小
一致性哈希算法以及其PHP实现详细解析
PHP如何利用P3P实现跨域
测试PHP连接MYSQL成功与否的代码
PHP 通过Socket收发十六进制数据的实现代码
PHP计算2点经纬度之间的距离代码
php 删除目录下N分钟前创建的所有文件的实现代码
php中如何判断一个网页请求是ajax请求还是普通请求
Ajax+PHP快速上手及简单应用说明
thinkphp 一个页面使用2次分页的实现方法
PHP分页效率终结版(推荐)
解析CI的AJAX分页 另类实现方法
基于PHP+Ajax实现表单验证的详解
AJAX的跨域访问-两种有效的解决方法介绍
关于使用coreseek并为其做分页的介绍
用php制作简单分页(从数据库读取记录)的方法详解
PHP header()函数使用详细(301、404等错误设置)
关于Iframe如何跨域访问Cookie和Session的解决方法
做了CDN获取用户真实IP的函数代码(PHP与Asp设置方式)
如何用PHP实现插入排序?
简单的php数据库操作类代码(增,删,改,查)
PHP插入排序实现代码
精美漂亮的php分页类代码
php页面跳转代码 输入网址跳转到你定义的页面
PHP 数组和字符串互相转换实现方法
php实现单链表的实例代码
ajax取消挂起请求的处理方法
PHP中使用cURL实现Get和Post请求的方法
ajax php传递和接收变量实现思路及代码
仿Aspnetpager的一个PHP分页类代码 附源码下载
php中长文章分页显示实现代码
PHP 利用AJAX获取网页并输出的实现代码(Zjmainstay)
php 解决旧系统 查出所有数据分页的类
无JS,完全php面向过程数据分页实现代码
php+ajax做仿百度搜索下拉自动提示框(有实例)
ajax在joomla中的原生态应用代码