Created
September 15, 2011 15:31
-
-
Save drewwells/1219564 to your computer and use it in GitHub Desktop.
Merge data from many AJAX requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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