Guest User

Untitled

a guest
Jan 23rd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. // Makes sequential getJSON requests, passing the processed results from the
  2. // previous request to the next request. seedData is optional.
  3. var chainedGetJSON = function(requests, seedData) {
  4. var seed = $.Deferred(),
  5. finalPromise;
  6.  
  7. finalPromise = requests.reduce(function(promise, request) {
  8. return promise.pipe(function(input) {
  9. return $.getJSON(request.url(input)).pipe(function(json) {
  10. return request.process(json, input);
  11. });
  12. });
  13. }, seed.promise());
  14.  
  15. // Start the chain
  16. seed.resolve(seedData);
  17.  
  18. return finalPromise;
  19. };
Add Comment
Please, Sign In to add comment