刷新 Div 的内容

Refresh content of a Div

我已阅读多篇关于通过使用 Jquery 重新加载 div 内容的帖子。我有一个带有多个浮动 div 的仪表板,它可以轮换在 php 脚本中计算的数据。

即。我有一个计算数据的 php 脚本,我将其包含在 div 中,然后滚动浏览内容(见下面的代码)

在线提供的代码示例存在的问题是它没有显示我的 php 内容。

我怎样才能重新加载 div 中的 php 页面并继续播放我的幻灯片?

提前致谢

<div class="topdiv_1">
    <div id="topdiv_1_slideshow">
        <div align="center">
            <img src="images/elements/project.png" class="pull-left" alt="" height="100px" style="padding-left: 10px; margin-top: 50px;">
            <h1 style="font-size: 90px; color: #ffffff; font-weight: bold"><?php include_once('topdiv_1_stat1.php') ?></h1>
            <h6 style="font-size: 14px; color: #ffffff; font-weight: bold">Project Hours Total</h6>
        </div>
        <div align="center">
            <img src="images/elements/project.png" class="pull-left" alt="" height="100px"
                 style="padding-left: 10px; margin-top: 50px;">

            <h1 style="font-size: 90px; color: #ffffff; font-weight: bold"><?php include_once('topdiv_1_stat2.php') ?></h1>
            <h6 style="font-size: 14px; color: #ffffff; font-weight: bold">Project Hours System Center</h6>
        </div>
        <div align="center">
            <img src="images/elements/project.png" class="pull-left" alt="" height="100px"
                 style="padding-left: 10px; margin-top: 50px;">

            <h1 style="font-size: 90px; color: #ffffff; font-weight: bold"><?php include_once('topdiv_1_stat3.php') ?></h1>
            <h6 style="font-size: 14px; color: #ffffff; font-weight: bold">Project Hours Service Center</h6>
        </div>
    </div>
</div>

更新:

我曾尝试将此代码添加到 div 但现在它丢弃了返回值的格式:

<div id="topdiv_1_slideshow">
        <div align="center" id="1">
            <img src="images/elements/project.png" class="pull-left" alt="" height="100px" style="padding-left: 10px; margin-top: 50px;">
            <h1 style="font-size: 90px; color: #ffffff; font-weight: bold"><?php /*include_once('topdiv_1_stat1.php') */?>
                <script>
                    $(function(){
                    $("#1").load("topdiv_1_stat1.php");
                    });
                </script>

                </h1>
            <h6 style="font-size: 14px; color: #ffffff; font-weight: bold">Project Hours Total</h6>
        </div>

您可以使用 Ajax 调用 php 脚本,获取数据并在您想要的 DOM 元素中显示 PHP 脚本返回的所有数据,这将用新数据刷新它。

但是如果没有javascript,你不能只刷新页面的一部分。

您的代码:

$("#1").load("topdiv_1_stat1.php");

将加载 topdiv_1_stat1.php 脚本的原始输出。

这意味着该响应中指向样式表的链接将不会像您在浏览器中打开页面时那样加载。

确保您的脚本 "topdiv_1_stat1.php" 仅 returns 您想要的 html 在 #1 div 中。