Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/435.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript获取文件内容循环_Javascript_Php_Jquery_Html - Fatal编程技术网

Javascript获取文件内容循环

Javascript获取文件内容循环,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我一直在尝试让函数每秒重新加载一次 我可以通过php获取文件内容(和重新加载元页面)来实现这一点,但我也使用JS来显示时间,加载时它不是即时的,因此它具有闪烁效果 我已经用JS试过了,但是没有显示任何效果 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Vivarium Enviroment Control Centre</title> <

我一直在尝试让函数每秒重新加载一次

我可以通过php获取文件内容(和重新加载元页面)来实现这一点,但我也使用JS来显示时间,加载时它不是即时的,因此它具有闪烁效果

我已经用JS试过了,但是没有显示任何效果

    <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Vivarium Enviroment Control Centre</title>
<link rel="stylesheet" href="style.css">
<script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
<script type="text/javascript">
    function updateTime() {
        var currentTime = new Date();
        var hours = currentTime.getHours();
        var minutes = currentTime.getMinutes();
        var seconds = currentTime.getSeconds();
        if (minutes < 10){
            minutes = "0" + minutes;
        }
        if (seconds < 10){
            seconds = "0" + seconds;
        }
        var v = hours + ":" + minutes + ":" + seconds + " ";
        if(hours > 11){
            v+="PM";
        } else {
            v+="AM"
        }
        setTimeout("updateTime()",1000);
        document.getElementById('time').innerHTML=v;
    }
updateTime();

$("document").ready(function(){
    setInterval(function(){
        $("#wifi").load('wifiout.php');
    },1000);
});


function changeStatus() {
    var image = document.getElementById('lightStatus');
    if (image.src.match("lightoff")) {
        image.src = "lighton.png";
    } else {
        image.src = "lightoff.png";
    }
}
</script>
</head>
<body>
<div id="topbar">
    <span id="time"></span>
    <div id="wifi"></div>
    <img id="lightStatus" class="right" onclick="changeStatus()" src="lightoff.png" width="32" height="32">
</div>
</body>
</html>

维瓦里姆环境控制中心
函数updateTime(){
var currentTime=新日期();
var hours=currentTime.getHours();
var minutes=currentTime.getMinutes();
var seconds=currentTime.getSeconds();
如果(分钟<10){
分钟=“0”+分钟;
}
如果(秒<10){
秒=“0”+秒;
}
变量v=小时+“:“+分钟+”:“+秒+”;
如果(小时数>11){
v+=“PM”;
}否则{
v+=“AM”
}
setTimeout(“updateTime()”,1000);
document.getElementById('time').innerHTML=v;
}
updateTime();
$(“文档”).ready(函数(){
setInterval(函数(){
$(“#wifi”).load('wifiout.php');
},1000);
});
函数changeStatus(){
var image=document.getElementById('lightStatus');
if(image.src.match(“lightoff”)){
image.src=“lighton.png”;
}否则{
image.src=“lightoff.png”;
}
}

如果缺少jQuery插件声明,请在脚本标记前添加以下行:

<script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>

注意:在ready函数中调用
updateTime()
函数,否则会出现以下错误:

TypeError:无法将属性“innerHTML”设置为null

因为您试图在页面尚未完全加载时使用span
time


希望这会有所帮助。

您使用的是jQuery语法,但我看不到它包含在内?这是我以前从未做过的事情,所以很有可能。Q已更新以反映所做的更改。文件
wifiout.php
只包含一个图像标记,它没有显示在页面上。这里的工作示例,检查我的更新问题出现在
updateTime()
call中。