I have this simple function in javascript to refresh a page after a set time.
function AutoRefresh( t ) {
setTimeout("location.reload(true);", t);
}
Now after every refresh, I want it to call a PHP function, for example:
function writeName()
{
echo "Refresh me";
}
Is it possible to call the PHP function in JavaScript after every refresh?
Thanks
If you are refreshing the page, you’re effectively reloading it from the server, so any ‘onload’ events will fire again. The page will render again from scratch. You can call a PHP script using AJAX in some ‘onload’ Javascript listener if you like, though. e.g. with JQuery:
Beware of calling setTimeout() recursively though as it can make a page unresponsive over time. You may find this useful:
http://www.erichynds.com/javascript/a-recursive-settimeout-pattern/