cliftonbazaar Posted April 2, 2013 Share Posted April 2, 2013 Hi all, I have the following function that refreshes sections of my code each two seconds - and it works fine. Now I wish for another part to refresh every 1 second, the following code keeps everything refreshing at 2 seconds. I have tried to rename the var to refreshID2 (didn't work ). How do I get this working correctly? //This is our Javascript function that allows us to constantly reload a page if we are involved in a match. $(document).ready(function() { $("#autoRefreshMatchStatus").load('game/gameplay/showCurrentGame.php'); $("#autoRunGame").load('game/gm/rungame/main.php'); $("#currentTime").load('game/functions/current_time.php'); var refreshId = setInterval(function() { $("#autoRefreshMatchStatus").load('game/gameplay/showCurrentGame.php'); $("#autoRunGame").load('game/gm/rungame/main.php'); }, 2000); var refreshId = setInterval(function() { $("#currentTime").load('game/functions/current_time.php'); }, 1000); $.ajaxSetup({ cache: false }); }); Quote Link to comment https://forums.phpfreaks.com/topic/276403-refreshing-page-each-second/ Share on other sites More sharing options...
kicken Posted April 2, 2013 Share Posted April 2, 2013 Trying to fire off an ajax request every second (or even every two seconds) is not really the best of ideas. It puts a lot of extra load on the server and requires a pretty fast connection to even happen. Ideally you should find a way update the page without so many requests. Since your once-per-second item seems to just be a clock value, rather than make an ajax request every second, just have JS update the clock on it's own (get current time, add a second, update display). You can run an ajax request once a minute or so the keep the clock in sync with the server if desired/necessary. Quote Link to comment https://forums.phpfreaks.com/topic/276403-refreshing-page-each-second/#findComment-1422388 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.