Mootools:等到所有ajax请求完成

时间:2013-09-14 01:24:51

标签: ajax mootools

这与Wait until all jQuery Ajax requests are done?非常相似,只是我想知道在Mootools中这样做的最佳做法。

1 个答案:

答案 0 :(得分:2)

http://mootools.net/docs/more/Request/Request.Queue

  

除了这些事件之外,还有一个onEnd事件在所有请求完成时被触发。

我将从文档中扩展示例:

var myRequests = {
    r1: new Request({
        url: '/foo1.php', data: { foo1: 'bar1'},
        onComplete: function(text, xml){
            console.log('myRequests.r1: ', text, xml);
        }
    }),
    r2: new Request({
        url: '/foo2.php', data: { foo2: 'bar2'},
        onComplete: function(text, xml){
            console.log('myRequests.r2: ', text, xml);
        }
    })
};
var myQueue = new Request.Queue({
    requests: myRequests,
    concurrent: myRequests.length,
    onEnd: function() {
        console.log('Everything is done!');
    },
    onComplete: function(name, instance, text, xml){
        console.log('queue: ' + name + ' response: ', text, xml);
    }
});

myQueue.send();