php 无刷新分页
来源:互联网 发布:监控矩阵 编辑:程序博客网 时间:2024/03/28 23:29
首先看无刷新分页效果:
(一)
(二)
比较一二两副图可以看出,下面文字部分的翻页了,但是整个页面并没有刷新,视频依然正常播放下去。
无刷新的关键思路:
首页,上一页,下一页,尾页。点击时,调用onclick事件,然后跳转到另外一张AJAX处理页,同时传入页码参数,处理页返回满足接收页码参数的信息,并且将首页,上一页,下一页,尾页那段代码也原样返回。其实就是在一个特定的DIV里变化分页的结果而已。
以往分页都是提交本页面,需要刷新一次,而无刷新就是利用了AJAX,给每个翻页添加了一个点击函数,交给了另外一个处理页。
代码如下:
显示页indexx.php:
<?php
include_once("function.php");
if($_GET['page'] == '')
{
$_GET['page'] = 1;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="js/xmlhttp.js" type="text/javascript"></script>
<script src="js/fenye.js" type="text/javascript"></script>
</head>
<body>
<div style="width:900px; height:auto; margin:auto;">
<embed src="http://player.youku.com/player.php/Type/Folder/Fid/6039532/Ob/1/Pt/0/sid/XMjY0NzY1NjQw/v.swf" quality="high" width="480" height="400" align="middle" allowScriptAccess="allways" mode="transparent" type="application/x-shockwave-flash"></embed>
</div>
<div id="fenye" style="width:900px; height:auto; border:1px solid #FF0000; margin:auto;">
<?php
if($_GET['page'])
{
$contenter = iconv("gb2312","utf-8",file_get_contents('file/mr_synopsis.txt'));
$length = strlen(unhtml($contenter));
$pageCount = ceil($length/950);
$prePage = msubstr($contenter,0,($_GET['page']-1)*950);
$nowPage = msubstr($contenter,0,$_GET['page']*950);
echo substr($nowPage,strlen($prePage),strlen($nowPage)-strlen($prePage));
}
?>
<div style="width:900px;height:30px; margin:auto; background:#FFFF99;">
<span>
页次:<?php echo $_GET['page']; ?>/<?php echo $pageCount; ?>页
</span>
<a href="#" onclick='return fenye("indexxok.php?page=1")'>首页</a>
<?php
if($_GET['page'] > 1 && $_GET['page'] <= $pageCount)
{
?>
<a href="#" onclick="return fenye('indexxok.php?page=<?php echo $_GET["page"]-1; ?>')">上一页</a>
<?php
}
?>
<?php
if($_GET['page'] >= 1 && $_GET['page'] < $pageCount)
{
?>
<a href="#" onclick="return fenye('indexxok.php?page=<?php echo $_GET["page"]+1; ?>')">下一页</a>
<?php
}
?>
<a href="#" onclick="return fenye('indexxok.php?page=<?php echo $pageCount; ?>')">尾页</a>
</div>
</div>
</body>
</html>
function.php:
<?php
function unhtml($content)
{
$content = htmlspecialchars($content); //转换文本中的特殊字符
$content = str_replace(chr(13),"<br>",$content); //替换文本中的换行符
$content = str_replace(chr(32)," ",$content); //替换文本中的
$content = str_replace("[_[","<",$content); //替换文本中的大于号
$content = str_replace(")_)",">",$content); //替换文本中的小于号
$content = str_replace("|_|"," ",$content); //替换文本中的空格
$content = trim($content); //删除文本中首尾的空格
return $content;
}
function msubstr($str,$start,$len) //定义一个用于截取一段字符串的函数msubstr()
{ //$str指的是字符串,$start指的是字符串的起始位置,$len指的是长度。
$strlen = $start+$len; //用$strlen存储字符串的总长度(从字符串的起始位置到字符串的总长度)
$tmpstr = ''; //定义变量$tmpstr
for($i=0;$i<$strlen;$i++) //通过for循环语句,循环读取字符串
{
if(ord(substr($str,$i,1)) > 0xa0) //如果字符串中首个字节的ASCII序数值大于0xa0,则表示为汉字,ord() 函数返回字符串第一个字符的 ASCII 值。
{
$tmpstr .= substr($str,$i,2); //每次取出两位字节赋给变量$tmpstr,即等于一个汉字
$i++; //变量自加1
}
else //如果不是汉字,则每次取出一位字符赋给变量$tmpstr
{
$tmpstr .=substr($str,$i,1);
}
}
return $tmpstr;
}
?>
indexxok.php:
<?php
include_once("function.php");
if($_GET['page'] == '')
{
$_GET['page'] = 1;
}
if($_GET['page'])
{
$contenter = iconv("gb2312","utf-8",file_get_contents('file/mr_synopsis.txt'));
$length = strlen(unhtml($contenter));
$pageCount = ceil($length/950);
$prePage = msubstr($contenter,0,($_GET['page']-1)*950);
$nowPage = msubstr($contenter,0,$_GET['page']*950);
echo substr($nowPage,strlen($prePage),strlen($nowPage)-strlen($prePage));
}
?>
<div style="width:900px;height:30px; margin:auto; background:#FFFF99;">
<span>
页次:<?php echo $_GET['page']; ?>/<?php echo $pageCount; ?>页
</span>
<a href="#" onclick='return fenye("indexxok.php?page=1")'>首页</a>
<?php
if($_GET['page'] > 1 && $_GET['page'] <= $pageCount)
{
?>
<a href="#" onclick="return fenye('indexxok.php?page=<?php echo $_GET["page"]-1; ?>')">上一页</a>
<?php
}
?>
<?php
if($_GET['page'] >= 1 && $_GET['page'] < $pageCount)
{
?>
<a href="#" onclick="return fenye('indexxok.php?page=<?php echo $_GET["page"]+1; ?>')">下一页</a>
<?php
}
?>
<a href="#" onclick="return fenye('indexxok.php?page=<?php echo $pageCount; ?>')">尾页</a>
</div>
- php 无刷新分页
- ajax+php写的无刷新分页
- jquery+PHP实现无刷新页面分页
- php ajax jquery 无刷新分页
- AJAX + PHP + MYSQL 实现无刷新分页
- PHP-Ajax实现无刷新分页
- PHP中的AJAX无刷新分页
- 无刷新分页PHP服务器端代码
- jQuery+Ajax+PHP无刷新分页
- Ajax+PHP实现无刷新分页效果
- PHP + AJAX 实现无刷新分页 不刷新页面实现分页 PHP AJAX
- PHP + AJAX 实现无刷新分页 不刷新页面实现分页 PHP AJAX
- 无刷新分页控件
- Repeater 无刷新分页
- 无刷新分页
- Repeater无刷新分页
- 分页无刷新
- ajax 无刷新分页
- api-example.c图像保存黑白转彩色
- make 中的config详述
- java序列化原则
- ++和——在c语言中应注意的一些小问题
- 解决:Android中 Error generating final archive: Debug Certificate expired
- php 无刷新分页
- ASP.Net需要了解的web知识
- 【zz】Q9 新手问答
- 通过SQL语句访问远程数据库
- VirtualBox使用教程图解
- JavaEE 事务管理器
- 每日一句,每日10词【1】(14天)
- FI初学者重难点汇集
- Linux目录结构