javascript - PHP refresh table without refresh entire page - Stack Overflow

I have a PHP page with one table that show any information in it. That information is refreshed every t

I have a PHP page with one table that show any information in it. That information is refreshed every three secs. Now I've found this solution for refresh the table:

<?php
echo "<div>Wele!</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>

in this way the html result is correct, the page is correctly updated every 3 secs, but after the first update happens a strange thing:

Html result:

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

So, all that I had before the refreshed div, now I have them inside the div. Where I'm wrong?

I have a PHP page with one table that show any information in it. That information is refreshed every three secs. Now I've found this solution for refresh the table:

<?php
echo "<div>Wele!</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>

in this way the html result is correct, the page is correctly updated every 3 secs, but after the first update happens a strange thing:

Html result:

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

So, all that I had before the refreshed div, now I have them inside the div. Where I'm wrong?

Share edited Aug 17, 2017 at 12:02 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Dec 22, 2013 at 11:35 user2174050user2174050 651 gold badge2 silver badges10 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 3

If I'm not wrong you're calling the same file again so you could try to do this instead,

index.php

<?php
echo "<div>Wele!</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>";
?>

seems that you load the result of index.php into div#infos

either make a php that ONLY generates the table you like to load or consider a general HTTP refresh - which will reload the entire page

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742286462a4415411.html

相关推荐

  • javascript - PHP refresh table without refresh entire page - Stack Overflow

    I have a PHP page with one table that show any information in it. That information is refreshed every t

    20小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信