Created
July 18, 2012 13:00
-
-
Save rd13/3136066 to your computer and use it in GitHub Desktop.
jQuery multiple deferreds
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
/* 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