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.
            Asked
            
        
        
            Active
            
        
            Viewed 540 times
        
    2
            
            
        - 
                    Mootools is compatible with jQuery, so you should be able to do exactly the same thing as described in the post you linked. See http://stackoverflow.com/questions/10100057/is-it-possible-to-use-mootools-and-jquery-both-together – Robert Harvey Sep 14 '13 at 01:28
- 
                    Does Mootools itself provide any methods for this? – twimo Sep 14 '13 at 01:32
- 
                    I don't see one in the documentation, no. – Robert Harvey Sep 14 '13 at 02:51
- 
                    1@RobertHarvey you can wrap request in a 3rd party promises/flow api but it's not out of the box. Request.Queue is a halfway solution. – Dimitar Christoff Sep 14 '13 at 04:46
1 Answers
2
            
            
        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();
 
    
    
        000
        
- 26,951
- 10
- 71
- 101
 
    