php 自动更新时间(在页面动态显示时间)
2012-01-20 17:28
916 查看
time.php:
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
</head>
<body>
<h1>Ajax动态显示时间</h1>
<input type="button" value="开始显示时间" id="go" onclick="start()" />
<p>当前时间:<font color="red"><span id="showtime"></span></font></p>
</body>
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
function start(){
createXMLHttpRequest();
var url="getTime.php";
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange = callback;
xmlHttp.send(null);
}
function callback(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
document.getElementById("showtime").innerHTML = xmlHttp.responseText;
setTimeout("start()",1000);
}
}
}
</script>
</html>
getTime.php:
<?php
header("cache-control:no-cache,must-revalidate");
header("Content-Type:text/html;charset=utf-8");
$showtime = date("北京时间Y年m月d日H:i:s");
echo $showtime;
?>
在浏览器调用time.php这个文件就可以了。
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
</head>
<body>
<h1>Ajax动态显示时间</h1>
<input type="button" value="开始显示时间" id="go" onclick="start()" />
<p>当前时间:<font color="red"><span id="showtime"></span></font></p>
</body>
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
function start(){
createXMLHttpRequest();
var url="getTime.php";
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange = callback;
xmlHttp.send(null);
}
function callback(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
document.getElementById("showtime").innerHTML = xmlHttp.responseText;
setTimeout("start()",1000);
}
}
}
</script>
</html>
getTime.php:
<?php
header("cache-control:no-cache,must-revalidate");
header("Content-Type:text/html;charset=utf-8");
$showtime = date("北京时间Y年m月d日H:i:s");
echo $showtime;
?>
在浏览器调用time.php这个文件就可以了。
相关文章推荐
- 如何在页面上显示当前时间(动态更新)
- 自动记录、显示页面更新时间
- 页面加载时显示日期时间星期几并自动更新
- jsp页面动态显示当前时间
- JSP实现几秒后自动跳转某页面并页面上显示时间在走动
- 使用js代码在aspx页面动态显示当前日期和时间
- 模拟js的首页动态推荐页面 Gallery 自动播放 无限循环 指示器显示 点击事件
- php显示动态时间源代码
- jQuery+PHP动态显示(项目)实时时间和倒计时
- php自动更新版权信息显示的方法
- js实现动态获取系统时间,显示到页面上
- jsp页面动态显示时间
- 实现Web页面中级联菜单的设计/实现动态加载列表框/实现自动刷新页面/实现Web页面的局部动态更新/实现自动完成功能
- 用javascript自动显示最后更新时间
- 在JSP页面中显示动态时间
- Ajax+php实现动态显示时间
- Java从服务器上获取时间动态显示在jsp页面实现思路
- JSP 页面动态的显示当前系统时间
- 模拟js的首页动态推荐页面 Gallery 自动播放 无限循环 指示器显示 点击事件
- jsp动态显示系统时间页面