Login Register

setTimeout and ajax call

I have a simple module like this:

dojo.provide("custom.ReportMonitor");
dojo.require("dojo.string");
(function () {
var rpt_type = "";
var exMode;
var path_;
var timerID;
var isFinished = false;
custom.ReportMonitor.doMonitor = function (type, mode, path) {
rpt_type = type;
exMode = mode;
path_ = path;
custom.ReportMonitor.poll();
};
custom.ReportMonitor.poll = function () {
if (timerID) {
clearTimeout(timerID);
}
if (!isFinished) {
timerID = setTimeout("custom.ReportMonitor.poll()", 2000);
}
custom.ReportMonitor.doXhr();
};
custom.ReportMonitor.doXhr = function () {
dojo.xhrGet({
handleAs:"json", url:"ReportMonitor",
content:dojo.queryToObject("rpt_type=" + rpt_type + "&mode=" + exMode + "&path=" + path_),
load:function (response, ioArgs) {
if (response.url) {
var template = "Download";
dojo.byId("content").innerHTML = dojo.string.substitute(template, response);
isFinished = true;
}
return response;
}, error:function (response, ioArgs) {
console.log("failed xhrGet", response, ioArgs);
return response;
}});
};
})();

in my html page i call the main function in this way:
dojo.require("custom.ReportMonitor");
var type = '${rpt_type}';
dojo.addOnLoad(function(){
custom.ReportMonitor.doMonitor(type);
});

In IE the custom.ReportMonitor.doXhr function is called only the first time,
and the setTimeout("custom.ReportMonitor.poll()", 2000); seems doesn't work.
In Firefox everything works fine.
Any suggestion?

Thanks.