Jump to content

Recommended Posts

Hello.

 

I am in need of some help:)

 

 

I know how to set up an interval, but now i need to clear it. So i thought u guys could help me out:)

 

I set my interval like this

 

setInterval(function(){
loadUpdateLevelPercentage();
}, 10000);

 

How can i clear it after 40 seconds?

Link to comment
https://forums.phpfreaks.com/topic/274687-clearinterval/
Share on other sites

@kicken: I think the issue is in 'how' to implement that after 40 seconds.

 

Well, there are a few options. This is the easiest in my opinion is this:

 

You apparently only want it to run 4 times since each interval is set to 10 seconds. So, set a global counter that is used inside loadUpdateLevelPercentage(). Then at the end of each iteration of the function, increment the counter and do a check to see how many times it has executed. If >= 4 then use clearInterval()

Link to comment
https://forums.phpfreaks.com/topic/274687-clearinterval/#findComment-1413401
Share on other sites

@Psycho: Aye, guess I didn't read close enough.

 

@Pain:

As a side note, there is one caution warning to be aware of with setInterval.  If it's possible that the time needed to run your code would be longer than the delay, you should use setTimeout instead to prevent overlapping / queued up calls to the function.

 

With a 10-sec delay that probably isn't an issue for you, though if you're doing any ajax work in the callback you might consider changing formats.

 

 

Link to comment
https://forums.phpfreaks.com/topic/274687-clearinterval/#findComment-1413410
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.