如何在PHP中使用间隔刷新div - php

问题:如何自动刷新div?以下是我的代码,但无法正常工作。有解决这个问题的主意吗???

下面的代码是我要自动刷新的主要脚本

<table id="auction-bidhist" class="table table-striped table-bordered">
                        <tbody>
                        <tr>

                            <td class="">Bid Price</td>

                            <td class="">Bidder Name</td>

                            <td class="">Time &amp; Date</td>

                            <td class="">Bid Type</td>


                        </tr>

                        <?php
                            $querySelectBidHistory = "SELECT * FROM bidhistory INNER JOIN useraccount ON bidhistory.Bid_userId = useraccount.userID WHERE Bid_auctionItemId = :bid ORDER BY Bid_id DESC LIMIT 10"; 
                            $stmtSelectBidHistory = $conn->prepare($querySelectBidHistory);
                            $stmtSelectBidHistory->bindParam(':bid',$_GET['id']);
                            $stmtSelectBidHistory->execute();
                            $rowCountSelectBidHistory = $stmtSelectBidHistory->rowCount();

                            if($rowCountSelectBidHistory > 0){

                                while($rowSelectBidHistory = $stmtSelectBidHistory->fetch()){

                            ?>
                                    <tr>

                                        <td><?php echo $rowSelectBidHistory['Bid_price']; ?></td>

                                        <td><?php echo $rowSelectBidHistory['userFullname']; ?></td>

                                        <td><?php echo $rowSelectBidHistory['Bid_time']; ?></td>

                                        <td><?php echo $rowSelectBidHistory['Bid_type']; ?></td>

                                    </tr>

                            <?php
                             }
                            }else{
                                    echo '  <tr>
                            <td class="text-center" colspan="4">No Bids as of Yet</td>
                        </tr>';
                            }
                            ?>




                        <tr>
                            <td colspan="4" class="text-center">The list will show last 10 bidder.</td>
                        </tr>

                    </tbody>
                    </table>

下面是刷新的代码

<script>
   $(document).ready(function(){
           setInterval(function() {
                 $("#auction-bidhist").load();
                }, 10000);
            });

</script>

任何更好的解决方案来解决这个问题???

参考方案

创建一个定位ID
加载刷新的URL。

javascript。

$(document).ready(function(){
    setInterval(function() {
        $.ajaxSetup({ cache: false });
        $("#targetId").load("auction-bidhist_File.php");
    }, 10000);
});

Auction-bidhist_File.php包括

<table id="auction-bidhist" class="table table-striped table-bordered">
                        <tbody>
                        <tr>

                            <td class="">Bid Price</td>

                            <td class="">Bidder Name</td>

                            <td class="">Time &amp; Date</td>

                            <td class="">Bid Type</td>


                        </tr>

                        <?php
                            $querySelectBidHistory = "SELECT * FROM bidhistory INNER JOIN useraccount ON bidhistory.Bid_userId = useraccount.userID WHERE Bid_auctionItemId = :bid ORDER BY Bid_id DESC LIMIT 10"; 
                            $stmtSelectBidHistory = $conn->prepare($querySelectBidHistory);
                            $stmtSelectBidHistory->bindParam(':bid',$_GET['id']);
                            $stmtSelectBidHistory->execute();
                            $rowCountSelectBidHistory = $stmtSelectBidHistory->rowCount();

                            if($rowCountSelectBidHistory > 0){

                                while($rowSelectBidHistory = $stmtSelectBidHistory->fetch()){

                            ?>
                                    <tr>

                                        <td><?php echo $rowSelectBidHistory['Bid_price']; ?></td>

                                        <td><?php echo $rowSelectBidHistory['userFullname']; ?></td>

                                        <td><?php echo $rowSelectBidHistory['Bid_time']; ?></td>

                                        <td><?php echo $rowSelectBidHistory['Bid_type']; ?></td>

                                    </tr>

                            <?php
                             }
                            }else{
                                    echo '  <tr>
                            <td class="text-center" colspan="4">No Bids as of Yet</td>
                        </tr>';
                            }
                            ?>




                        <tr>
                            <td colspan="4" class="text-center">The list will show last 10 bidder.</td>
                        </tr>

                    </tbody>
                    </table>

您实际的html

<div id="targetId">
<?php include "auction-bidhist_File.php"; ?>
</div>

jQuery如果选中则启用动态输入文本 - php

我正在使用PHP生成具有表格的表格,例如:<table class="table table-hover"> <thead> <tr> <th class="table-checkbox"> </th> <th> Description </…

Div单击与单选按钮相同吗? - php

有没有一种方法可以使div上的click事件与表单环境中的单选按钮相同?我只希望下面的div提交值,单选按钮很丑代码输出如下:<input id="radio-2011-06-08" value="2011-06-08" type="radio" name="radio_date&#…

PHP-复选框组 - php

我有一个需要发布的表单复选框组。<input type="checkbox" value="true" checked name="chk0[]"> <input type="checkbox" value="false" name=…

添加php代码时未包含jQuery源文件 - php

该代码运行良好,但是在我添加了以下php代码之后,一切都掉了。我添加了如下所示的php代码后,它为jquery-1.11.3.js指出“无法加载资源”。我在这里完全迷路了。不知道这是怎么了。<?php $currentMonthInInteger = date("n"); $currentYear = date("Y�…

php Singleton类实例将在多个会话中保留吗? - php

举一个简单的例子,如果我想计算一个不使用磁盘存储的脚本的命中次数,我可以使用静态类成员来执行此操作吗?用户1:<?php $test = Example::singleton(); $test->visits++; ?> 用户2:<?php $test = Example::singleton(); $test->visits+…