php

位置:IT落伍者 >> php >> 浏览文章

php+ajax实现页面自动刷新时间


发布日期:2020年12月02日
 
php+ajax实现页面自动刷新时间

indexphp

view plaincopy to clipboardprint?
<mce:script type="text/javascript"><!
var xmlHttp;
function createXMLHttpRequest(){
if(windowActiveXObject){
xmlHttp = new ActiveXObject("MicrosoftXMLHTTP");
}
else if(windowXMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
function start(){
createXMLHttpRequest();
var url="getTimephp";
xmlHttpopen("GET"urltrue);
xmlHttponreadystatechange = callback;
xmlHttpsend(null);
}
function callback(){
if(xmlHttpreadyState == ){
if(xmlHttpstatus == ){
documentgetElementById("showtime")innerHTML = xmlHttpresponseText;
setTimeout("start()");
}
}
}
// ></mce:script>


<html>
<head>
<meta httpequiv="contenttype" content="text/html;charset=gb" />
</head>
<body>
<h>Ajax动态显示时间</h>
<input type="button" value="开始显示时间" id="go" onclick="start()" />
<p>当前时间<font color="red"><span id="showtime"></span></font></p>
</body>
</html>
<mce:script type="text/javascript"><!
var xmlHttp;
function createXMLHttpRequest(){
if(windowActiveXObject){
xmlHttp = new ActiveXObject("MicrosoftXMLHTTP");
}
else if(windowXMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
function start(){
createXMLHttpRequest();
var url="getTimephp";
xmlHttpopen("GET"urltrue);
xmlHttponreadystatechange = callback;
xmlHttpsend(null);
}
function callback(){
if(xmlHttpreadyState == ){
if(xmlHttpstatus == ){
documentgetElementById("showtime")innerHTML = xmlHttpresponseText;
setTimeout("start()");
}
}
}
// ></mce:script>


<html>
<head>
<meta httpequiv="contenttype" content="text/html;charset=gb" />
</head>
<body>
<h>Ajax动态显示时间</h>
<input type="button" value="开始显示时间" id="go" onclick="start()" />
<p>当前时间<font color="red"><span id="showtime"></span></font></p>
</body>
</html>

getTimephp


view plaincopy to clipboardprint?
<?php
header("cachecontrol:nocachemustrevalidate");
header("ContentType:text/html;charset=gb");
$showtime = date("北京时间Y年m月d日H:i:s");
echo $showtime;
?>

上一篇:解析php通过cookies获取远程网页的指定代码

下一篇:怎样去阅读一份php源代码