jQuery 轮询
xuexi 2026-04-04 00:23:20 发表在:PHP 查看数:6
// 轮询 每1秒请求一次后台接口,更新数据
setInterval(() => {
    fetch('/get-data')
        .then(res => res.json())
        .then(data => {
            // 渲染到页面:替换你的DOM元素ID即可
            document.getElementById('totalUsageSum').innerText =data.pos;
            document.getElementById('currentTime').innerText = data.currentTime;
            document.getElementById('deviceCount').innerText = data.deviceCount;
            document.getElementById('alarmCount').innerText = data.alarmCount;
        });
}, 5000);
</script>


setInterval(function(){
    $.get('/data', function(res){
        $('#list').html(res);
    });
}, 5000);
最近访问时间:2026-04-04 02:11:11
知识库:438条鸣谢:TAY  备案号:蜀ICP备2024090044号