I would like to update a table cell for a status obtained from a jsp method. The method takes some time, hence it isn’t instant. Therefore I need ajax to refresh the page to get an updated status once the method completes
<script type="text/javascript">
function updateTable()
{
var xmlhttp;
var table = document.getElementById('theTable');
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById('theTable').innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open(???);
xmlhttp.send();
}
//Refresh every 2 seconds
setInterval( doStuff, 2000 );
</script>
<!-- The actual Table needed to updated -->
</TABLE>
<TABLE id="theTable">
<TH>status</TH>
<tr>
<td><%=status%></td>
</tr>
</table>
On the server you need a jsp page that generates the table data when it is invoked. Say this is called generatetable.jsp. You can then use that URL in the open() method to invoke the jsp page.
Your callback function will handle replacing the current table data with the new table data when it is received.