twimo
twimo

Reputation: 4217

Mootools: wait until all ajax requests are done

This is very similar to Wait until all jQuery Ajax requests are done?, except that I want to know the best practice of doing that in Mootools.

Upvotes: 2

Views: 545

Answers (1)

000
000

Reputation: 27247

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

In addition to these events there is an onEnd event that is fired when all the requests have finished.

I'm going to extend the example from the documentation:

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();

Upvotes: 2

Related Questions