I come to you in need of help. If anyone could help me out, I'd greatly appreciate it.

Problem:When I click "End", it doesn't destroy (lack of a better word) the setTimeout function.You'll notice the json file is called, at some point 6 times

Note:I left a console.log in the code to show you the issue I speak of (so ensure you have your console open).

Requirements:By default the json file should load once, then upon clicking "Start", the json file needs to be called (every x secs) until "End" is clicked (in which case the polling will stop).

AussieJohn
—
2011-12-04T05:37:44Z —
#2

I just had a quick look at your example page and everything seemed to work just fine. Are you still having an issue?

If you're talking about the number that's returned by console.log(_this.setPolling), that's the ID of the setTimeOut not the # of times it's been called.

scripting_semantics
—
2011-12-04T05:49:40Z —
#3

Hi,

Thanks for the quick response (that's good to know). If you click "Start" & "End" a few times, you'll see the number of requests (json) double, if not triple. Let me know if you can't replicate the issue. Keep clicking a few times and you'll see.

Thanks again for your expertise.

AussieJohn
—
2011-12-04T05:57:43Z —
#4

Ah, I see. It looks as if it's starting the polling setTimeOut multiple times.

I think the most straightforward way to get around that is to check if _this.setPolling is defined.

In addition to this, you will want to delete the reference to the timeout once it's been cleared, i.e.