PHP refresh table without refreshing whole page

I have a PHP page with one table that contains all the information. This information is updated every three seconds. Now I found this solution to update the table:

<?php
echo "<div>Welcome!</div>";
echo "<div align= \"center\" id=\"infos\">";    
echo "<table border= \"1\">";
...
echo "</table>";
echo "</div>";
?>

<script type="text/javascript">

$(document).ready (function () {
    var updater = setTimeout (function () {
        $('div#infos').load ('index.php', 'update=true').scrollTop(lastScrollPos);
        }, 3000);
});
</script>

thus, the html result is correct, the page is refreshed every 3 seconds, but after the first refresh the strange thing happens:

HTML Result:

<div>Welcome!</div>
<div align= "center" id="infos">    
<div>Welcome!</div>
<div align= "center" id="infos">    
<table border= "1">
...
</table>
</div>

So, all that I had before the updated div, now I have them inside the div. Where am I mistaken?

+4
source share
2 answers

If I'm not mistaken, you call the same file again to try to do this,

index.php

<?php
echo "<div>Welcome!</div>";
echo "<div align= \"center\" id=\"infos\">";    
echo "<table border= \"1\">";
...
echo "</table>";
echo "</div>";
?>

<script type="text/javascript">

$(document).ready (function () {
    var updater = setTimeout (function () {
        $('div#infos').load ('table.php', 'update=true').scrollTop(lastScrollPos);
        }, 3000);
});
</script>

Table.php

<?php
echo "<table border= \"1\">";
...
echo "</table>";
echo "</div>";
?>
+3
source

, index.php div # infos

php, , HTTP,

0

All Articles