Jump to content

setinterval bad pracrise?


dianikol85

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.

Link to comment
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?

Link to comment
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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...