XMLHttpRequest takes more than 2 mintues to hit the server
I am running into a peculiar problem while using XMLHttpRequest. The scenario is: I have a page that loads report and some times it takes more than 30 minutes to load the report and show it to browser. In the meantime i want to give the progress feedback to my client. So, I have put the report page inside an IFrame of another page and when the button is clicked to generate the report I call window.parent.Status() and then return true for the post back to take place. Here is what the window.parent.Status() does.
function Status() {
LoadingPanel.Show();
GetStatus();
}
function GetStatus() {
var xmlHttp;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
}
catch (e) {
// Internet Explorer
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.open("GET", "Status.aspx", true);
xmlHttp.send();
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4) {
var msg = '';
var percentage = '';
if (xmlHttp.responseText == '') {
document.getElementById('dvStatus').innerHTML = 'Loading....';
开发者_运维知识库 }
else {
var resp = xmlHttp.responseText.split('$');
if (resp.length > 1) {
document.getElementById('dvStatus').innerHTML = resp[1];
if (resp[1] == 'Report layout built successfully') {
setTimeout('HideLoadingPanel()', 5000);
}
else {
setTimeout('GetStatus()', 1000);
}
}
}
}
}
}
function HideLoadingPanel() {
LoadingPanel.Hide();
document.getElementById('dvStatus').innerHTML = 'Loading....';
}
See, XMLHTTPRequest calls Status.aspx page and in on page load method some sessions are read and sends back the response back like this: Response.Write(percentage + "$" + message + " : " + percentage + "%" + "$");
Now the problem is: for the first time the XMLHttpRequest takes 2 minutes or more than 2 minutes to hit the page_load method of Status.aspx page. But once the first call happens, it does the call every second as the codes asks it to do. The problem is for the first call. Is the any body who can tell me what is the problem? I am really in trouble with this issue
Regards, Mohin
精彩评论