4

I've created a stock ticker function and need to call it every 2 minutes.

I've succeeded in doing this with the javascript setInterval function, but the problem is on the first call it waits 2 minutes before calling the function, whereas I want the first load to be called right away.

function CallFunction() { setInterval("GetFeed()", 2000); } 
1
  • 3
    FYI, the second parameter to setInterval is measured in milliseconds - 2000 is two seconds, and you'll want 120000 for two minutes (= 120 seconds * 1000 milliseconds/second). Commented Apr 22, 2010 at 15:00

3 Answers 3

6
 function CallFunction() { GetFeed(); setInterval("GetFeed()", 2000); } 
Sign up to request clarification or add additional context in comments.

1 Comment

my 2 cents setInterval(GetFeed, 2000);
3
function CallFunction() { GetFeed(); return setInterval(GetFeed, 2 * 60 * 1000); } var id = CallFunction(); 

Comments

0

The following snippet shown in image calls a function after every 20 seconds and it can be stopped by calling cancelRepeat() function. Hope this helps.

enter image description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.