jquery - refreshing php variable with JS -
i have problem refreshing php variable... php variable after refreshing still same - not refreshed
my little js:
var reload = function() { var pred = <?php echo json_encode(reload()); ?>; $(".reload").fadein("fast").text(pred); settimeout(reload, 3000); } settimeout(reload, 3000);
my php function:
function reload() { foreach ($servers $server) { $s = explode(":", $server); $data = $status->getstatus($s[0], $s[1]); if (!$data) {} else { $c1 = $c1 + $data['players']; } } return $c1; //players returned }
if joined game after during script variable same on beggining... nothing changed. why variable isn't refreshing ? doing wrong?
thanks , sorry bad eng
reload()
called once: when script executes first time. php processing completed on server side before output (including html , javascript) sent browser.
when javascript function executes, re-uses value produced reload()
first time script ran.
if want generate new value via php, either need refresh page or create ajax call fetch fresh data server.
Comments
Post a Comment