I am trying to create 2 buttons, 1 to start the script and 1 to stop it.
var timerID = setInterval(function() {
$.ajax({
url: "script.php",
context: document.body
});
}, 60 * 1000);
clearInterval(timerID);
I have no idea how i would have to call this , this is what i was trying:
<button id="id" onClick="timerID();"></button>
You'll want to wrap it inside another function:
var timerID;
var myTimerFn = function () {
timerID = setInterval(function() {
$.ajax({
url: "script.php",
context: document.body
});
}, 60 * 1000);
};
// call
myTimerFn();
Then another function to close it. Or pass a parameter to tell it whether to start or stop.
I suppose you want to start and stop the timer?
var timerID ;
function start()
{
var timerID = setInterval(function() {
$.ajax({
url: "script.php",
context: document.body
});
}, 60 * 1000);
}
function stop()
{
clearTimeout(timerID );
}
This is how you would call it:
<button id="start" onClick="start();"></button>
<button id="stop" onClick="stop();"></button>
For more information about setInterval
check here: http://www.w3schools.com/js/js_timing.asp