Skip to content

Instantly share code, notes, and snippets.

@rd13
Created July 18, 2012 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rd13/3136066 to your computer and use it in GitHub Desktop.
Save rd13/3136066 to your computer and use it in GitHub Desktop.
jQuery multiple deferreds
/* http://jsfiddle.net/Zp3MZ/1/ */
$(function() {
var objs = [{'one':1},{'two':2},{'three':3}];
ajaxCall = function(i) {
return $.ajax({
url:'/echo/html/',
method: 'POST',
data: {id:i}
}).done(function (data) {
console.log('ajax call');
});
}
$.when.apply($,
objs.map(function(i) {
return ajaxCall(i);
})
).then(function(response) {
console.log('all done');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment