Problems refreshing page with AJAX
Hello,
I have never used AJAX but today I decided to try it to improve my current implementation of a "processing" page that I use to display a waiting message and to check every 5 seconds if a response is available. If it is, the user is redirected to a "processing done" page.
My previous implementation used the refresh tag provided by HTML in the "processing" page:
<meta HTTP-EQUIV="Refresh" CONTENT="5; URL=<%=request.getContextPath()%>/main/CheckForResponse.do"/>
Every 5 seconds a struts action is executed and the action itself will forward to the "processing done" page when a response is available.
This solution works, however I don't like the refresh page effect, so I was trying to use AJAX instead. Now I put in the "processing" page the following script:
function checkForResponse()
{
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!");
returnfalse;
}
}
}
xmlHttp.open("GET","<%=request.getContextPath()%>/main/CheckForResponse.do",true);
xmlHttp.send(null);
}
and I have the following html body tag.
<body onLoad="setInterval('checkForResponse()',5000);">
The function executes correctly and the struts action is also executed. However the problem is that for some reason the action doesn't forward to the "processing done" page. It does actually, if I debug, but nothing happens, the "waiting" page keeps being displayed.
Does anyone have an idea about what I could be doing wrong? any suggestion?
Thanks a lot!!

