I have a simple JS timer which runs every 10 seconds and should send an AJAX request. The problem is that on some windows XP machines this task stops running – no AJAX request is sent. It seems to run successfully for 45 minutes and then stop for a random amount of time, then start and run successfully for another 45 minutes…my question is what could be causing this to happen? Could some service/scheduled task running on the PC stop javascript timers from working?
Ext.onReady(function(){
var task = {
run: function(){
Ext.Ajax.request({
url: 'test.php'
});
},
interval: 10000
};
Ext.TaskManager.start(task);
});
Couple of suggestions:
Try to switch from
Ext.TaskManagerto a normalsetInterval. If that fixes the problem there’s probably a bug in Task Manager.If it doesn’t work then try the following:
Keep using intervals. Record the
idof the interval. Also record the time of last execution.Start another timer with
setIntervaland larger interval, say 1 minute. Inside the callback check for the last execution time.If it was long ago (> 30 seconds), call
clearIntervalwith theidthat you stored and restart the task interval.If that doesn’t work try executing these polling tasks in a separate
<iframe>. A browser can skip calling Interval and Timeout callbacks if it’s busy with other tasks. By putting them into a separate<iframe>you give them a dedicated event loop, so that other tasks won’t interfere with them.