计时器java脚本在本地服务器上运行正常。但是当我在托管服务器上运行它时,它不会启动计时器。
<script type="text/javascript" >
<?php
$elapsed=time()-strtotime($_SESSION['starttime']);
if(((int)$elapsed/60)<(int)$_SESSION['duration'])
{
$result=executeQuery("SELECT " .
" TIME_FORMAT(TIMEDIFF(endtime,CURRENT_TIMESTAMP),'%H') as hour, ".
" TIME_FORMAT(TIMEDIFF(endtime,CURRENT_TIMESTAMP),'%i') as min, ".
" TIME_FORMAT(TIMEDIFF(endtime,CURRENT_TIMESTAMP),'%s') as sec ".
" FROM studenttest ".
" WHERE stdid=".$_SESSION['stdid'].
" AND testid=".$_SESSION['testid'].";");
if($rslt=mysql_fetch_array($result))
{
echo "var hour=".$rslt['hour'].";";
echo "var min=".$rslt['min'].";";
echo "var sec=".$rslt['sec'].";";
} else {
$_GLOBALS['message']="Try Again";
}
closedb();
} else {
echo "var sec=01;var min=00;var hour=00;";
}
?>
</script>
答案 0 :(得分:0)
替换
<?php
使用
<?php
session_start();
答案 1 :(得分:0)
更多地清理你的代码后,堆栈溢出代码突出显示你的php输出被注释标记包围:
<!-- -->
所以javascript永远不会看到PHP回显的变量。这可能是你的问题吗?