首页 > 解决方案 > 用内容刷新网页的一部分

问题描述

我正在使用网页作为客户端,并且我正在寻找一个程序来刷新页面的一部分而不是整个页面。这部分由日历组成。我试过下面的代码:

('#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 秒刷新一次日历表,不带内容。

我想实时刷新带有数据(内容)的日历。

标签: javascriptjqueryajax

解决方案


您可以使用纯 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>

或者你可以使用一个框架。你可以使用像vue.js这样简单而直接的,或者像react这样更复杂的,给你更多的灵活性。


推荐阅读