如何在php中使用interval刷新div

时间:2016-01-18 16:21:28

标签: php jquery

问题:如何自动刷新div?下面是我的代码,但无法工作。有什么想法解决这个问题????

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

{{ area.details.get_full_information|truncatechars:30 }} 

以下是要刷新的代码

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

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

1 个答案:

答案 0 :(得分:0)

  1. 创建定位ID
  2. 加载刷新的网址。
  3. 的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>