简体   繁体   中英

JQUERY - Ajax.Load - Multiple Scripts

well i have a problem, im using Ajax with Jquery, using the Jquery.Load() function. Happens that i want to have a "countdown" javascript on a certain page. The problem is, when i call that page with ajax, it does all normally, but if i click the link again, the countdown doubles speed, if i do again it keeps going faster and faster. There is some script to flush the old script and start again? or to not load again the script? Thankyou

It sounds like something is calling either setInterval or setTimeout every time you $.load . That code would need to be modified so that it the countdown is only started once. Since you haven't pasted your code, all I can suggest is something that looks like this...

if (!window.timerId) {
    window.timerId = setInterval(callback, interval);
}

// later, when the countdown is over:
window.timerId = null;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM