Diskusie » Vývoj

repeat executung script

§
Pridaný: 23.09.2015

repeat executung script

hi, for example i have a ajax request, how i can repeat the request every 1 minute? thank you.

woxxomZablokovaný
§
Pridaný: 23.09.2015
Upravený: 23.09.2015
  • Use setInterval to automatically call the specified function periodically:

    var interval = setInterval(function() {
       // do ajax request
       ...............
    }, 60 * 1000);
    
    if (some_condition) {
        clearInterval(interval); // stop the timer
    }
    
  • Use setTimeout to schedule one run of the function based on condition:

    var timeout;
    (function doAjax() {
       // do ajax request
       ...............
       if (some_condition) {
           timeout = setTimeout(doAjax, 60 * 1000); // schedule the next run
       }
    })();
    
    if (another_condition) {
        clearTimeout(timeout); // cancel the schedule
    }
    
§
Pridaný: 23.09.2015

thank you wOxxOm!, you are good for a teacher :D

Pridať odpoveď

Aby ste mohli pridať odpoveď, prihláste sa.