After a long struggle with jQuery countdown plugin I still cannot solve it, but at least I know why it happens.
Before I explain it any further please take a look at this example and try reproducing the problem:
- Try clicking on GMT link
- Countdown timer will show
- Next click on GMT+7
- GMT+7 timer will show but have an error…
On second load jQuery creates another instance in this case the timer and display it in the same div. If you continue to click on it, it will create more and more objects.
How can I solve this? I’ve been struggling with it for 5 hours now.
How can I reset/kill the object or something. So it won’t crash.
Any help from you guys is greatly appreciated.
Thanks, Ivan
Checking your example
I can see that your Ajax request returns some HTML as well as some script (document ready ?!?!) that creates a new instance of countdown plugin.
Suggested solution
Why don’t you instead just return JSON data and manipulate existing countdown plugin that’s already loaded/running in the browser window? It seems you should then just run these function in this order:
stopCountDown()setCountDown( /* target date data */ )startCountDownas suggested in countdown plugin documentation example.
I’ve actually tried running these three functions using Firebug and it correctly stopeed reset and started the same plugins instance.
My suggestion is therefore: Your Ajax request should return JSON of the
targetDateobject that can be used directly withsetCountDown()function.