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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.