I have a JS function. I want it to be paused after it's first-time execution for 10s, and after that time I want to resume it.
So, what I have done is:
$( "#button_yes,#button_no" ).click(function()
{
if(counter)
{
console.log('Done');
$.ajax(
{
url: baseURL+"add_votes",
success: function(result)
{
counter=0;
alert(result);
setTimeout(check, 10000); //set a 10s delay
counter=1;
},
method: "POST",
data:
{
id : '1'
},
});
}
});
But it I not working perfectly. It prevents the function executing second time permanently if I click multiple times.
Is there any solution?