Created
August 24, 2011 16:08
-
-
Save baconpat/1168407 to your computer and use it in GitHub Desktop.
JavaScript function for making sequential 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
// Makes sequential getJSON requests, passing the processed results from the | |
// previous request to the next request. seedData is optional. | |
var chainedGetJSON = function(requests, seedData) { | |
var seed = $.Deferred(), | |
finalPromise; | |
finalPromise = requests.reduce(function(promise, request) { | |
return promise.pipe(function(input) { | |
return $.getJSON(request.url(input)).pipe(function(json) { | |
return request.process(json, input); | |
}); | |
}); | |
}, seed.promise()); | |
// Start the chain | |
seed.resolve(seedData); | |
return finalPromise; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment