<script>
//when page is ready do the following
$(document).ready(function()
{
//set interval of refresh
setInterval(doAjaxMethod, 1000);
});
function doAjaxMethod(id)
{
$.ajax({
url: "getStatus/"+id,
dataType: "json",
success: function(json)
{
$('#ajaxStatus').html(json.status);
}
});
</script>
<%
//How can I do something like this
int n = object.size();
for(int i=0; i<n; i++)
{
doAjaxMethod(object.getId());
}
%>
<div id=ajaxStatus> status updates here </div>
<script> //when page is ready do the following $(document).ready(function() { //set interval of refresh
Share
I would not mix calling javascript from within scriplets. Instead, manage the loop in javascript. If you describe more of what you are trying to do, I can be more specific. It seems you have an container object available on the jsp, and you need to loop thru to get the statuses of what is in the container. Instead of passing that object to the jsp, why don’t you create an endpoint that the javascript on the jsp can invoke in ajax to get ALL the data you need.