public
Created

Merge data from many AJAX requests

  • Download Gist
nResolve.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
function aj( url ){
 
return $.ajax({
url: url,
success: function( data ){
}
);
}
 
function resolve( args ){
//Create call $.when( url1, url2, url3 )
var defer = $.when.apply( $, $.map( args, aj ) );
return defer.pipe(function(){
//Return data instead of success arguments
// (data,status,browser ajax obj)
return $.map( arguments, function( n, i ){
return n[0];
});
});
}
 
resolve(['url1','url2','url3'])
.then(function( url1data, url2data, url3data ){
//Will map to console.log above
console.log( 'then', arguments );
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.