How To Automatically Call Javascript Function Every Hour?
I have a javascript function that gets a JSON object from a URL and I want to refresh the JSON object every hour with up to date data. I am assuming the way to do this is to recal
Solution 1:
function doSomething()
{
alert('Test');
}
setInterval(doSomething, 60*60*1000);
Solution 2:
You could re-call your function with setting an interval:
<scripttype="text/javascript">functiongetJSONObjectFromURL(){
// do stuff
}
//set interval in milliseconds and call function again//1h = 60m = 3600s = 3600000msvar timeoutID = window.setInterval(getJSONObjectFromURL, 3600000);
</script>
Solution 3:
You may try:
setInterval(function(){alert("Hello")},3600000);
Where 3600000 is the time interval in miliseconds.
Solution 4:
Go with setInterval
as shown below :-
Syntax
setInterval(function,milliseconds,lang)
Parameter Values
Parameter Description
function Required. The function that will be executed
milliseconds Required. The intervals (in milliseconds) on how often to execute the code
lang Optional. JScript | VBScript | JavaScript
Return Value
An integer with the ID value of the timer that is set. Use this value with the clearInterval() method to cancel the timer.
Example
function test()
{
////Your code
}
setInterval(function(){test()}, 60 * 60 *1000); //// 60 minutes = 3600 seconds = 3600000 miliseconds
For more details :-
Post a Comment for "How To Automatically Call Javascript Function Every Hour?"