Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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;
- };
Add Comment
Please, Sign In to add comment