更新:如果您使用 jQuery,我已经了解了一个更好的答案,请参阅标题下的更新:Using jQuery Deffered
旧答案:
您还可以使用Array.reduceRight(当它可用时)来包装$.ajax调用并将列表转换为:[resource1, resource2]到$.ajax({url:resource1,success: function(...) { $ajax({url: resource2...(我从 Haskell 中学到的一个技巧,它是 fold/foldRight 函数)。
下面是一个例子:
var withResources = function(resources, callback) {
    var responses = [];
    var chainedAjaxCalls = resources.reduceRight(function(previousValue, currentValue, index, array) {
        return function() {
            $.ajax({url: currentValue, success: function(data) {
                responses.push(data);
                previousValue();
            }})
        }
    }, function() { callback.apply(null, responses); });
    chainedAjaxCalls();
};
然后你可以使用:
withResources(['/api/resource1', '/api/resource2'], function(response1, response2) {
    // called only if the ajax call is successful with resource1 and resource2
});
使用 jQuery 延迟
如果您使用的是 jQuery,则可以通过使用以下函数来利用jQuery DefferedjQuery.when():
 jQuery.when($.get('/api/one'), $.get('/api/two'))
       .done(function(result1, result2) { 
              /* one and two is done */
        });