javascript - 用内容刷新网页的一部分
问题描述
我正在使用网页作为客户端,并且我正在寻找一个程序来刷新页面的一部分而不是整个页面。这部分由日历组成。我试过下面的代码:
('#caldiv').fadeOut('slow').load('/Global-Appointment/Scripts/fullcalendar.js.php').fadeIn('slow'); (1000);
('#caldiv').fadeOut('slow').load('/Global-Appointment/Scripts/fullcalendar.js.php').fadeIn('slow'); (1000);
上面的脚本仅每 1 秒刷新一次日历表,不带内容。
我想实时刷新带有数据(内容)的日历。
解决方案
您可以使用纯 JS 来实现:
<html>
<div id="where-data-will-be-shown"></div>
</html>
[...]
<script>
setInterval(async () => { // Create an interval
const data = JSON.parse(await (await fetch("/where-data-comes-from")).text());
document.getElementById("where-data-will-be-shown").innerHTML = data;
}, 1000)
</script>
推荐阅读
- javascript - 如何在 Node.js 中复制数组的元素?
- terminology - 是否有其他(原始)类型的字符串版本的计算机科学术语?
- php - PHP OOP 可见性区域
- php - 我需要从提交 URL 的 GET 表单操作中删除“+id”以正确重定向
- python - SQLAlchemy 中所有行的高效更新
- python - 在 Python 中计算每日平均值(一天对一个变量有多个值)
- python - 我怎样才能让它从数组中选择一个随机数,但每次都选择不同的数字?
- ios - 在 SwiftUI 中构建一个自定义的类 TabView 视图
- visual-studio-code - 如何使用命令行在 VSCode 中安装多个扩展
- sorting - 对电子元件列表进行排序?