Skip to content

Instantly share code, notes, and snippets.

@drewwells
Created September 15, 2011 15:31
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save drewwells/1219564 to your computer and use it in GitHub Desktop.
Merge data from many AJAX requests
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 );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment