<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>
0
A
回答
3
我不会在scriplets中混合调用javascript。相反,在JavaScript中管理循环。如果你更多地描述你想要做的事情,我可以更具体一些。看起来你在jsp上有一个容器对象,你需要循环直到获取容器中的状态。为什么不创建jsp上的javascript可以在ajax中调用的端点来获取所需的所有数据,而不是将该对象传递给jsp。
0
试试这个(假设objArray
是一个数组):
$.each(objArray, function(i, obj) {
doAjaxMethod(obj.getId());
});
它会遍历你的阵列和obj
是每一个项目。 希望它有帮助。
2
你可以做的一种方法是将它们添加到像css类的对象列表中,并触发其上的ajax方法onLoad
。 下面是一些未经检验的(可能未编译)
<%
//How can I do something like this
int n = object.size();
for(int i=0; i<n; i++)
{
out.println("<li class='abcd' id ='<%=object.getId()%>'>" +object.getId() +"</li>");
}
%>
,然后在页面加载的JavaScript
$(function(){
$('.abc').each(i, v){
doAjaxMethod($(v).attr('id'));
}
});
相关问题
- 1. 使用jQuery AJAX请求在while循环
- 2. 我怎么循环在我的JSP响应使用jQuery
- 3. 如何使用jquery循环我的ajax请求?
- 4. 我怎么使用jQuery AJAX
- 5. 在循环中发送jquery ajax请求
- 6. 使用循环的Ajax请求
- 7. 循环内的Ajax请求
- 8. Ajax请求的循环
- 9. AJAX url请求循环
- 10. 在循环中使用JQuery同步Ajax请求
- 11. 在一个jQuery AJAX请求使用for循环
- 12. jquery和ajax请求
- 13. 我怎么能循环使用Excel VBA
- 14. 我怎么使用jQuery的Ajax方法
- 15. 使用JQuery和Ajax获取HTTP请求
- 16. 使用Ajax POST请求和jQuery
- 17. 使用jQuery的AJAX请求
- 18. 通过循环使用jQuery和Ajax
- 19. 我的循环怎么了?
- 20. Javascript - 循环内的AJAX请求
- 21. 防止假循环Ajax请求到PHP
- 22. ajax请求正在Angularjs中循环
- 23. AJAX请求PHP脚本循环
- 24. for循环..等待AJAX请求
- 25. 使用jquery ajax和自动请求有什么作用?
- 26. 为什么我的post jQuery Ajax请求会使用JSON?
- 27. 跨域请求和jQuery/AJAX
- 28. jQuery的AJAX请求和PHP
- 29. Angular和jQuery Ajax请求
- 30. jquery Button,Knockout.js和ajax请求
你想的AJAX事件,每隔几秒钟或什么火?请在这方面澄清你的问题。 – Bojangles