Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

So I have a table pulling information from a database and I was wondering how I could make it refresh its information without reloading the whole page.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
660 views
Welcome To Ask or Share your Answers For Others

1 Answer

You'll need a getTable.php page that displays your table, and nothing else: no headers, footers, etc.

PHP (getTable.php) - this can be any server side code (asp, html, etc..)

<?php
    echo '<table><tr><td>TEST</td></tr></table>';
?>

Then, in your JS, you can easily refresh the table by using the load() method:

HTML

<div id="tableHolder"></div>

JS

<script type="text/javascript">
    $(document).ready(function(){
      refreshTable();
    });

    function refreshTable(){
        $('#tableHolder').load('getTable.php', function(){
           setTimeout(refreshTable, 5000);
        });
    }
</script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...