刷新Div的内容

问题描述:

I have read through multiple posts regarding reloading the content of a div through the use of Jquery. I have a Dashboard with multiple floating divs that rotates data calculated in php scripts.

ie. i have a php script that calculates data and i include this in a div which then scrolls through the content (see below code)

The problem i have with the code examples available online is that it doesnt show my php content.

How can i go about reloading the php pages in the div and still keep my slideshow going?

Thanks in advance

<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>

UPDATE:

I have tried adding this code to the div but now it throws away the formatting of the returned value:

<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>

Your code:

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

will load the raw output of the topdiv_1_stat1.php script.

That means that links to stylesheets in that response will not be loaded as they would when you open the page in your browser.

Make sure your script "topdiv_1_stat1.php"only returns the html that you want in the #1 div.

You can call a php script with Ajax, get the datas and show all the datas returned by the PHP script in the DOM element you want, that will refresh it with fresh datas.

But you can't refresh only a part of your page without javascript.