我需要通过AJAX从多个来源(xml或JSON格式)收集数据,然后运行一个使用这些数据集的函数。
在执行函数之前,如何检查所有AJAX调用是否都成功?理想情况下,我希望保持异步调用,以最大限度地减少响应时间。
发布于 2011-08-10 09:51:17
从概念上讲,它的工作原理是这样的:
ajax调用的一些伪代码:
results = [];
$.ajax({
// other parameters here
success: function(data) {
results.push(data);
checkResults();
};
});
function checkResults() {
// if all five results are in, then we're ready to process them
if (results.length >= 5) {
processResults(results);
}
}
https://stackoverflow.com/questions/7005053
复制相似问题