Call javascript function at regular intervals

I created a stock ticker function and should call it every 2 minutes.

I managed to do this with the javascript setInterval function, but the problem is the first call, which it waits 2 minutes before the function call, while I need to call the first request right away.

 function CallFunction() { setInterval("GetFeed()", 2000); } 
+4
source share
3 answers
  function CallFunction () {
         GetFeed ();
         setInterval ("GetFeed ()", 2000);
     }
+6
source
 function CallFunction() { GetFeed(); return setInterval(GetFeed, 2 * 60 * 1000); } var id = CallFunction(); 
+3
source

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

enter image description here

0
source

Source: https://habr.com/ru/post/1307689/


All Articles