Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call a javascript function at distinct time intervals

Tags:

javascript

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);
}
like image 870
Dkong Avatar asked Jan 22 '23 05:01

Dkong


2 Answers

function CallFunction() {
        GetFeed();
        setInterval("GetFeed()", 2000);
    }
like image 67
Senad Meškin Avatar answered Feb 01 '23 12:02

Senad Meškin


function CallFunction() {
  GetFeed();
  return setInterval(GetFeed, 2 * 60 * 1000);
}

var id = CallFunction();
like image 23
aekeus Avatar answered Feb 01 '23 12:02

aekeus