很多站长朋友们都不太清楚phpajax计时,今天小编就来给大家整理phpajax计时,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 PHP怎么制作计时器 2、 php ajax循环到计时显示一句话 3、 ajax+php 如何获取当前时间 4、 php中怎样实现倒计时功能 5、 求PHP+ajax 倒 计时程序 PHP怎么制作计时器计时器的运用在网页制作中很普遍,其实计时器有很多做法,PHP加JS、JS加AJAX也可以控制实现。不是PHP可以单独实现的,因为PHP是实现服务端的语言,没有办法去控制。以下实例就是制作计时器的代码:
<SCRIPT language=JAVASCRIPT>
var timerID = null;
var timerRunning = false;
function stopclock()
{
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}
function startclock()
{
stopclock();
showtime();
}
function showtime()
{
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()
var timeValue = "" +hours;
//定时初始化数据库的代码:
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
document.Calc.time.value = timeValue;
// you could replace the above with this
// and have a clock on the status bar:
// window.status = timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
return '';
}</script>
客服端PHP+HTML代码:
<html>
< head>
< META HTTP-EQUIV="Refresh" Content="1;URL=test.php">
< /head>
< body>
< ?
echo date("Y年m月d日 H时i分s秒");
?>
</body>
</html>
php ajax循环到计时显示一句话那直接在客户端用js倒计时就是了嘛。
服务器只判断一下开始时间和结束时间就好了嘛。
ajax+php 如何获取当前时间主要产生原因是你的缓存控制到了。
简单的方法:在你的ajax调用url地址后面加上一个随机函数。 例如你的代码的这句:
xmlHttp.open("GET","time.php",true);
改成:
xmlHttp.open("GET","time.php?"+Math.random(),true);
还有另外一种就是在time.php里面header一个no-cache出来也是可以的。 不过这个方法麻烦又有点多余啦。
php中怎样实现倒计时功能可以考虑asp实现:
1.HiddenField 控件储存时间
<!--2700秒时间-->
<asp:HiddenField ID="hidTime" runat="server" Value="2700" />
2.js代码
<script language="javascript" type="text/javascript">
var time;
var minutes;
var seconds;
var str;
function ShowTime2() {
if(document.getElementById("btnSubmitExam") !=null)
{
time = document.getElementById("hidTime").value;
time = time - 1;
document.getElementById("hidTime").value = time;
minutes = parseInt(time / 60);
seconds = time % 60;
document.getElementById("DjTimeDiv").innerHTML = "剩余时间:" + minutes + "分钟" + seconds + "秒";
if (time == 1) {
document.getElementById("DjTimeDiv").innerHTML="剩余时间:0分钟0秒";
document.getElementById ("btnSubmitExam").click();
// window.close();
}else
{
setTimeout("ShowTime2()", 1000);
}
}else
{
document.getElementById("DjTimeDiv").innerHTML="剩余时间:0分钟0秒";
}
}
</script>
求PHP+ajax 倒 计时程序当用户click时触发函数 getTime() 用ajax到服务器获取当前时间,然后从这个时间倒计时15秒 不知道楼主是不是这个意思。如果是这样的话不需要去服务器获取时间的,因为目的只是从用户click开始倒计时15秒。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>倒计时</title>
<script type="text/javascript">
var start = -1;
var tid = 0;
function begin(){
start = 15;
daojishi();
tid = setInterval(daojishi, 1000)
}
function daojishi(){
if(start > 0){
setValue('还剩:'+start+' 秒');
start--;
}else if(start == 0){
setValue('你已经等了15秒了');
clearInterval(tid);
return;
}
}
function setValue(str){
document.getElementById("timeless").innerHTML = str;
}
</script>
</head>
<body>
<input type="button" value="click me" onclick="begin()" />
<div id="timeless"></div>
</body>
</html>
关于phpajax计时的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。
查看更多关于phpajax计时 php时间加减的详细内容...