Skip to content Skip to sidebar Skip to footer

Ensure Only One Settimeout Runs (is Active) At A Time?

The recursive setTimeout function getRandomProducts is called onload in the html body tag, and so is constantly iterating.The function setCategoryTree is being called onclick from

Solution 1:

You are setting the variable t within the function. The next time this function gets called the var t will not be available for you.

Therefore, Set the variable above the function (not in it)

var randomProductsTimeout = false;

functiongetRandomProducts(category){

    randomProductsTimeout = setTimeout()[..]

Post a Comment for "Ensure Only One Settimeout Runs (is Active) At A Time?"