The problem is this:
when you turn the checkbox, a timer is on, turn off the checkbox and timer goes off. I’ve tried, but nothing try.
$('#apply').click(function () {
if ($('#autoupdate').prop("checked")) {
var timerId = setInterval(function () {
$.ajax({
type: "post",
url: "1.php",
cache: false,
success: function (html) {
$("#result").html(html);
}
});
}, 1000);
} else {clearInterval(timerId);}
});
Autoupdate: <input type="checkbox" id="autoupdate">
<input id="apply" type="submit" value="Apply">
<div id="result"></div>
You have to declare variable outside. like
and then put your code
cause if it’s declared inside
ifthen accessing variable timerId from else will not be possible, cause its undefined.