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).
You should call
completePoll()on click of “end” link.FYI: The
_this.completePoll(cfg);with in thesetTimeoutclears the previous timeout handler which has already executed.Also, if you called the
startPollfunction more than once, without clearing the current timeout, you will end up creating another timeout cycle and will overwrite the previous handler.Add the above line in the beginning of the
startPollfunction which will kill the running timer.