Jump to content

Refreshing page each second


cliftonbazaar

Recommended Posts

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 });
});



 

Link to comment
https://forums.phpfreaks.com/topic/276403-refreshing-page-each-second/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.