教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 php ajax 无刷新翻页实现代码

php ajax 无刷新翻页实现代码

发布时间:2016-10-27   编辑:jiaochengji.com
教程集为您提供php ajax 无刷新翻页实现代码等资源,欢迎您收藏本站,我们将为您提供最新的php ajax 无刷新翻页实现代码资源

下面只是一个测试,在实际应用中,可能这种方法会比较占系统资源,不建意利用这样的方法处理分页效果。

<blockquote>

var http_request=false;
function send_request(url){//初始化,指定处理函数,发送请求的函数
http_request=false;
//开始初始化xmlhttprequest对象
if(window.xmlhttprequest){//mozilla浏览器
http_request=new xmlhttprequest();
if(http_request.overridemimetype){//设置mime类别
http_request.overridemimetype("text/xml");
}
}
else if(window.activexobject){//ie浏览器
try{
http_request=new activexobject("msxml2.xmlhttp");
}catch(e){
try{
http_request=new activexobject("microsoft.xmlhttp");
}catch(e){}
}
}
if(!http_request){//异常,创建对象实例失败
window.alert("创建xmlhttp对象失败!");
return false;
}
http_request.onreadystatechange=processrequest;
//确定发送请求方式,url,及是否同步执行下段代码
http_request.open("get",url,true);
http_request.send(null);
}
//处理返回信息的函数
function processrequest(){
if(http_request.readystate==4){//判断对象状态
if(http_request.status==200){//信息已成功返回,开始处理信息
document.getelementbyid('result').innerhtml=http_request.responsetext;
}
else{//页面不正常
alert("您所请求的页面不正常!");
}
}
}
function dopage(obj,url){
document.getelementbyid(obj).innerhtml="正在读取数据...";
send_request(url);
reobj=obj;
}

</blockquote>

php教程 html处理代码

<blockquote>

<div id="result">
<?php
$classid=$_request['classid'];
//注意有个问题,就是数据如果总数小于每页数据不能显示

$page=isset($_get['page'])?intval($_get['page']):1; //这句就是获取page=18中的page的值,假如不存在page,那么页数就是1。
$num=10; //每页显示10条数据

require "conn.php";
mysql教程_select_db($database_lr, $lr);
/*
首先咱们要获取数据库教程中到底有多少数据,才能判断具体要分多少页,具体的公式就是
总数据库除以每页显示的条数,有余进一。
也就是说10/3=3.3333=4 有余数就要进一。
*/

$result=mysql_query("select * from blog where classid='$classid'");
$total=mysql_num_rows($result); //查询所有的数据

$url='show_main.php';//获取本页url

//页码计算
$pagenum=ceil($total/$num); //获得总页数,也是最后一页
$page=min($pagenum,$page);//获得首页
$prepg=$page-1;//上一页
$nextpg=($page==$pagenum ? 0 : $page 1);//下一页
$offset=($page-1)*$num; //获取limit的第一个参数的值,假如第一页则为(1-1)*10=0,第二页为(2-1)*10=10。

//开始分页导航条代码:
$pagenav=$page."/".$pagenum."&nbsp;<b>&nbsp;".($total?($offset 1):0)."</b>-<b>".min($offset 10,$total)."</b> &nbsp;total $total &nbsp;";

//第一页:
if($page==1) {
$pagenav.="first&nbsp;";
}
else
{$pagenav.="<a href=网页特效:dopage('result','$url?classid=$classid&page=1');>first</a>&nbsp;";}
if($prepg) $pagenav.=" <a href=javascript:dopage('result','$url?classid=$classid&page=$prepg');>prev</a>&nbsp;"; else $pagenav.=" prev&nbsp;";
if($nextpg) $pagenav.=" <a href=javascript:dopage('result','$url?classid=$classid&page=$nextpg');>next</a> "; else $pagenav.=" next ";
if ($pagenum>$page){
$pagenav.="&nbsp;<a href=javascript:dopage('result','$url?classid=$classid&page=$pagenum');>last</a> ";
}
else{
$pagenav.="&nbsp;last";
}
$pagenav.="&nbsp;total page $pagenum ";

//假如传入的页数参数大于总页数,则显示错误信息
if($page>$pagenum){
echo "error : can not found the page ".$page;
exit;
}

$info=mysql_query("select * from blog where classid='$classid' order by id desc limit $offset,$num"); //获取相应页数所需要显示的数据

if ($total>0)
{
while($it=mysql_fetch_array($info)){
echo $it['title']."&nbsp;(".$it['updatetime'].")";
echo "<br>";
echo $it['content'];
echo "<br>";
} //显示数据
echo"<br>";
echo $pagenav;//输出分页导航
}
else
{
echo"no comment.";
}
?>
</div>

</blockquote>

您可能感兴趣的文章:
jquery ajax 无刷新提交数据与无刷新登录的例子
通过pjax实现无刷新翻页(兼容新版jquery)
jQuery.Pjax
Jquery:ajax实现翻页无刷新功能代码
Jquery ajax无刷新翻页的实现代码
div li多行多列的无刷新分页代码
分享精心挑选的12款优秀jQuery Ajax分页插件和教程
jQuery Pagination Ajax分页插件(分页切换时无刷新与延迟)中文翻译版
Jquery ajax实现无刷新登录的方法介绍
基于jquery ajax 用户无刷新登录方法详解

[关闭]
~ ~