Scenario:
Whenever a user clicks on a cell within the "#test" table, the "update_func" function will run and repeat every 10 seconds.
If the user clicks on the same cell or another cell, multiple instances of "update_func" start running simultaneously every 10 seconds.
Inquiry:
To prevent multiple instances of "update_func" from running at the same time, where should I implement the clearTimeout() function in the code?
The existing script is as follows:
$("#test").on("click", td, function() {
//do something..
update_func(v1,v2,v3);
});
function update_func(v1,v2,v3){
$.ajax({
url:"update.php",
method:"POST",
data:{testvalue:v1},
success:function(data){
$('#testbox').html(data);
}
}).always(function () {
window.setTimeout(function() { update_func(v1,v2,v3); }, 10000);
});
}