开发者

AJAX variable refresh help

Im trying to find a way of refreshing a PHP variable on a webpage without reloading the entire page again, I just want the e开发者_JS百科choed variable to update at a set rate. Any help would be appretiated.

echo "Speed: " . ($APIkbpersec) . " KB/s";


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.

http://jquery.com/

<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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜