I have to execute particular code every 1 minute, I have coded like this. Below code is working in all browsers except in IE.
Issue is: ../common/ajaxpage.aspx is hitting very first time,from the next time is not hitting but timedcount is calling for every 1 minute and variable “data” returns “not elapsed” every time even though ajaxpage.aspx is not called.
var gt_t;
$(document).ready(function () {
gt_t = setTimeout('timedCount()', 60000);
OnSaveBtnFix();
OnStart();
alert(gt_t);
});
function timedCount() {
alert("timed count started");
$.get('../common/AjaxPage.aspx', { action: 'sessionexp', TypeID: 'ClientID' }, function (data) {
alert(data);
if (data == "Elapsed") {
dispalySessionPopup();
gt_t = setTimeout('timedCount()', 60000);
}
else if (data == "null") {
hidePopup('popupMsg');
document.location.href = "../Index.aspx?logout=y";
}
else {
gt_t = setTimeout('timedCount()', 60000);
}
});
}
IE is probably caching your request. You can convert your
$.getcall into a$.ajaxcall and use thecacheoption. jQuery will add a timestamp to the end of the request, forcing the browser to make a fresh request:As a side note, it is considered a best-practice to use the version of
setTimeoutthat takes a function reference, not a string. In other words:could/should be rewritten: