【发布时间】:2016-07-01 16:29:27
【问题描述】:
我有一个带有 Struts 2 的 JSP,包括:
<div id="data">
<s:include value="list.jsp"/>
</div>
list.jsp 里面有一个迭代器。
使用 JavaScript,我有 3 个函数可以对不同的操作和 Web 服务进行 Ajax 调用,但是这 3 个函数会刷新同一个 Java 对象列表:
function firstCall(product) {
// an ajax call
.done(function(html) {
$("#data").append(html);
});
}
function secondCall(product) {
// an ajax call
.done(function(html) {
$("#data").append(html);
});
}
function thirdCall(product) {
// an ajax call
.done(function(html) {
$("#data").append(html);
});
}
我还有另一个函数可以迭代产品的字符串数组:
function iterate(productos){
for(i=0;i<productos.length;i++){
firstCall(productos[i]);
secondCall(productos[i]);
thirdCall(productos[i]);
}
}
我的问题是我需要这三个方法是异步的,因为每个方法都需要大约 10 秒。 =(
有更好的方法吗?
【问题讨论】:
-
比什么好?目前尚不清楚问题是什么:您已经在进行异步调用;
firstCall返回,secondCall在firstCall的请求完成之前开始。有什么问题?在进行 DOM 操作之前是否需要等待所有这些都完成? -
为什么不调用每个函数(传递整个数组)一次,而不是调用每个函数(传递单个元素)的大量时间?无论有多少元素,你都会有 3 次调用,反对 n*3...只是说
-
产品总是很长 3。所以对于第一个产品,我需要 3async 调用,但我不知道该怎么做。当 3calls 完成后转到下一个产品。
标签: javascript ajax asynchronous struts2