javascript - setInterval doesn't seem to re-execute php script -
what i'm trying variable update every 5 seconds doing this:
setinterval(document.getelementbyid("listeners").innerhtml = "<?php include('../includes/shoutcaststuff.php'); echo $dnas_data['currentlisteners']; ?>",5000);
but happens inner html set doesn't update every 5 seconds should. guess php executes once, have no idea if that's case or not. , i'm aware should make function stuff inside setinterval... i'll clean code once figure out how make work. in advance.
ok... ajax 'the best' answer since no more 2 people logged in @ time here server requests isn't such big deal. here's how got work:
function lcount(){ $.get("../includes/shoutcaststuff.php",{count: "true"}, function(data){ document.getelementbyid('listeners').innerhtml = data; }); } setinterval(lcount,5000);
and added end of php:
if(isset($_get["count"])){ echo $dnas_data['currentlisteners']; }
now works fine.
thanks suggestions guys :)
<?php include('../includes/shoutcaststuff.php');
echo $dnas_data['currentlisteners']; ?>
this code executes once when page built. rest of times javascript called whatever first echoed value.
instead of using static value here, going need use ajax request (or websocket if want use html5). request hit server once every 5 seconds. keep in mind can cause undue load on server.
ratchet commonly used php websocket implementation allows data sent client using push technology. more preferable using polling approach.
Comments
Post a Comment