-
-
Save YCF/9a05ff00c4478076f57e to your computer and use it in GitHub Desktop.
Async jquery multi ajax
This file contains hidden or 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
define([ "when/parallel", "jquery" ], function (parallel, $) { | |
var tasks = [ "url1", "url2", "url3" ].map(function (url) { | |
return function () { | |
return $.get(url); | |
}; | |
}); | |
parallel(tasks) | |
.then(function (results) { | |
return results.reduce(function (sum, result) { | |
return sum + result.property; | |
}, 0) / results.length; | |
}) | |
.tap(function (result) { | |
alert(result); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment