Load script every X seconds

Asked

Viewed 49 times

1

I have an Odometer in JS that is powered by a notepad, so I needed to load the load.txt every 5 seconds or so...

I tried to use setTime() but it didn’t work very well!

Here’s the part I’d like to run every five seconds...

$("odometer").load("counter.txt");

Any idea?

1 answer

2

If you expect recursive behavior, you should use the setInterval()

function carregar()
{
  ///$("odometer").load("counter.txt");
  console.log('olar');
}

setInterval(carregar,5000);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.