Jump to content
Killersites Community
Sign in to follow this  
dianikol85

setinterval bad pracrise?

Recommended Posts

Hi to all!!

 

Here is my questiion:

 

i have this code

 

<script type="text/javascript">
$(document).ready(function(){
	get_current_song();
	setInterval("get_current_song()",5000);
});

function get_current_song(){
	$('#reload_now_play').load("load_song.php");
}
</script>

 

 

to load some text from another script .The content of load_song.php where i get the text, changes every 3-4 minutes. So i use the get_current_song() function every 5 secs by using the setInterval function. That works for this project but i think if the server for example get down for a while the above technique will return an empty string.

 

So i guess i have to use the $().load() function again after it comlete over and over and this will solve the bad timing problem. How should i write it??

 

Thanks.

Share this post


Link to post
Share on other sites
That works for this project but i think if the server for example get down for a while the above technique will return an empty string.

Technically, if the server is down, your users won't be able to access your site, including this script... Unless the Javascript you posted above and the "load_song.php" file will be on different domains/servers?

Share this post


Link to post
Share on other sites

Technically, if the server is down, your users won't be able to access your site, including this script... Unless the Javascript you posted above and the "load_song.php" file will be on different domains/servers?

 

The server example was a bad one. What i meant is if the response is lets say faster than the setinterval call

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×