Reputation: 1236
Im trying to find a way of refreshing a PHP variable on a webpage without reloading the entire page again, I just want the echoed variable to update at a set rate. Any help would be appretiated.
echo "Speed: " . ($APIkbpersec) . " KB/s";
Upvotes: 1
Views: 2737
Reputation: 2187
You would need to have that function in a seperate file and use an AJAX request to update it. The standard is jQuery so I will show a very basic example of usage.
<div id="Update">This will be updated</div>
$("#Update").load('YourUpdateScript.php');
This will request the php script and place the contents into the div named "Update".
To get it updating regulaly you need to have a timer set up:
// This is run when the document is ready, you could also run setInterval elsewhere if needed
$(document).ready(function (e) {
setInterval ( RunUpdate, 3000 ); // Run once every 3 seconds
});
function RunUpdate() {
$("#Update").load('YourUpdateScript.php');
}
A page refresh or calling clearInterval() will stop it from running.
Upvotes: 5