Using Setinterval With $(document).ready
Solution 1:
It should be:
$(document).ready(function () {
setInterval(function(){f()},3000);
});
The problem here is that setIntervalreturns a number, and passing a number to $(document).ready(...) does nothing. Instead, you need to pass $(document).ready(...) a function, such as a function that starts off the setInterval call.
The other problem is that you included a semicolon after the setInterval, but semicolons are only valid on statements (which you can think of as "things that stand on their own line"). You can only pass expressions to functions like setInterval, and expressions don't have semicolons, so your extra semicolon before the closing parenthesis is an error, because the JS engine sees a semicolon-terminated statement where it expects there to be a no-semicolon expression.
Also, you can shorten this to just
$(document).ready(function () {
setInterval(f, 3000);
});
or even
$(function () {
setInterval(f, 3000);
});
Post a Comment for "Using Setinterval With $(document).ready"