Ajax的无刷新分页
Ajax的无刷新分页
这里以两个文件进行代码显示一个是ajax分页实现的文件,另一个是分页类文件
文件1.ajax_page.php
<script type="text/javascript" language="javascript">
function createXMLHttp()
{
var browser=navigator.appName; //get the current browser
if(browser=="Microsoft Internet Explorer")
{
xmlHttp=new ActiveXObject("Microsoft.XMLHttp"); //if is IE
}
else xmlHttp=new XMLHttpRequest();
}
function changePage(url)
{
xmlHttp.onreadystatechange=newPage;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function newPage()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
document.getElementById("newPage").innerHTML=xmlHttp.responseText;
}
}
}
function doPage(url)
{
var xmlHttp=false;
createXMLHttp();
document.getElementById("newPage").innerHTML="正在读取数据...";
changePage(url);
}
</script>
<style type="text/css">
#pageWay{
background-color:#b5d6e6; background-image:url("tab_19.gif"); width:100%; font-size:15px; padding:5px;
}
span{
color:red; font-weight:700;
}
.one{
width:37px; height:15px;
}
.two{
width:43px; height:15px;
}
img{
border:0px;
}
</style>
<div id="newPage">
<?php
include "database.class.php";
include "page.class.php";
$db=new database();
$data_sql="SELECT `exptime`,`realdat`,`predat` from `labrec`";
$data_res=$db->query($data_sql) or die($db->error());
$data_nums=$db->num_rows($data_res); //求出总的数据条数
if($data_nums)
{
&nbs
相关文档:
1、在服务端加 header("Cache-Control: no-cache, must-revalidate");
2、在ajax发送请求前加上 xmlHttpRequest.setRequestHeader("If-Modified-Since","0");
3、在ajax发送请求前加上 xmlHttpRequest.setRequestHeader("Cache-Control","no-cache");
4、在 Ajax 的 URL 参数后加上 "?fresh=" + Math.rando ......
What is AJAX
This section is for those who have no idea what AJAX is. If you don’t fall into this category, feel free to skip to the next section.
AJAX stands for asynchronous JavaScript and XML. If you see another term XHR, which is shorthand for XML HTTP request, it’s the same thing. ......
多数 Web 应用程序都使用请求/响应模型从服务器上获得完整的 HTML 页面。常常是点击一个按钮,等待服务器响应,再点击另一个按钮,然后再等待,这样一个反复的过程。有了 Ajax 和 XMLHttpRequest 对象,就可以使用不必让用户等待服务器响应的请求/响应模型了。本文中,Brett McLaughlin 介绍了如何创建能够适应不同浏览器的 ......
对于很多 Web 开发人员来说,只需要生成简单的请求并接收简单的响应即可;但是对于希望掌握 Ajax 的开发人员来说,必须要全面理解 HTTP 状态代码、就绪状态和 XMLHttpRequest 对象。在本文中,Brett McLaughlin 将向您介绍各种状态代码,并展示浏览器如何对其进行处理,本文还给出了在 Ajax 中使用的比较少见的 HTTP 请求。 ......
Ajax的原理简单来说通过XmlHttpRequest对象来向服务器发异步请求,从服务器获得数据,然后用javascript来操作DOM而更新页面。这其中最关键的一步就是从服务器获得请求数据。要清楚这个过程和原理,我们必须对 XMLHttpRequest有所了解。
XMLHttpRequest是ajax的核心机制,它是在IE5中首先引入的,是一种支持异步请求的技术 ......