I have a PHP control panel I'm currently working on. I need a div in one of my PHP files to automatically refresh and I came across an jQuery solution which can automatically reload certain parts of a website. The problem is every time I include the script, when the setInterval runs it just turns the div into a blank element instead of loading the content.
My site works by having a master PHP called "panel.php" which loads various HTML documents (.php files) using "include". One of those HTML documents is called "printers.php".
Inside printers.php I want to reload this div:
<div id="tsd"><?php echo time(); ?></div>
So at the top of my code in the head tag of "printers.php" I added this code:
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script>
setInterval(function () {
$( "#tsd" ).load("panel.php #tsd");
}, 2000);
</script>
Now when the panel.php document loads, the timestamp shows for 2 seconds, then disappears and the div element just goes blank with no data in it. I can't figure out why it is reloading a blank div? Any ideas would help.
panel.phpyourself every 2 seconds?panel.phpcode correctly, try$('#tsd').load('panel.php?page=printers #tsd');If that works, let me know and i'll write up the reasoning behind it in an answer. (Don't think I can fit it in a comment)