ajax实现无刷新分页(php)

前端之家收集整理的这篇文章主要介绍了ajax实现无刷新分页(php)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<div class="codetitle"><a style="CURSOR: pointer" data="70690" class="copybut" id="copybut70690" onclick="doCopy('code70690')"> 代码如下:

<div class="codebody" id="code70690">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;


投票结果

<script type="text/javascript">
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox,Opera 8.0+,Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
function checkajax(){
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("您的浏览器不支持AJAX!");
return ;
}else
{
return xmlHttp;
}
}
function preshow(){
ajaxobj = checkajax();
var url = "page.PHP?page=1";
ajaxobj.onreadystatechange=stateChanged;
ajaxobj.open("GET",url,true);
ajaxobj.send(null);
}
function showHint1(str)
{
ajaxobj = checkajax();
document.getElementById("msg").innerHTML="正在读取数据……";
var url = str;
ajaxobj.onreadystatechange=stateChanged;
ajaxobj.open("GET",true);
ajaxobj.send(null);
}
function showHint2(str)
{
ajaxobj=checkajax();
document.getElementById("msg").innerHTML="正在读取数据……";
var url = str;
ajaxobj.onreadystatechange=stateChanged;
ajaxobj.open("GET",true);
ajaxobj.send(null);
}
function showHint3(str)
{
ajaxobj=checkajax();
document.getElementById("msg").innerHTML="正在读取数据……";
var url = str;
ajaxobj.onreadystatechange=stateChanged;
ajaxobj.open("GET",true);
ajaxobj.send(null);
}
function showHint4(str)
{document.getElementById("msg").style.display="none";
ajaxobj=checkajax();
document.getElementById("msg").innerHTML="正在读取数据……";
var url = str;
ajaxobj.onreadystatechange=stateChanged;
ajaxobj.open("GET",true);
ajaxobj.send(null);
}
function stateChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById("message").innerHTML=xmlHttp.responseText;
}
}


<body onload="preshow()">
<div id="wrapper">

用户留言如下:


<div id="message">





<div class="codetitle"><a style="CURSOR: pointer" data="62404" class="copybut" id="copybut62404" onclick="doCopy('code62404')"> 代码如下:
<div class="codebody" id="code62404">
<?PHP
$link = MysqL_connect('localhost','root','') or die(MysqL_error());
MysqL_select_db('vote',$link) or die(MysqL_error());
MysqL_query("set names utf8");
$num = 3;
$url = "page.PHP";
$con = "";
$con .= <<< PAGE
<p id="page"><a href="#" id="first" onclick="showHint1('$url?page=1')">首页|<a href="#" id="pre" onclick="showHint2('$url?page=$prepg')">上一页|<a href="#" id="next" onclick="showHint3('$url?page=$nextpg')">下一页|<a href="#" id="last" onclick="showHint4('$url?page=$pagenum')">尾页


PAGE;
echo $con;
?>

原文链接:https://www.f2er.com/ajax/28433.html
ajax分页分页分页无刷新

猜你在找的Ajax相关文章