Last active
March 11, 2016 16:28
-
-
Save joshuaebowling/eb173d9e6dbcba6cb259 to your computer and use it in GitHub Desktop.
Using Async.js for Ajax Flow Control
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
var records = [{data:'data1'}, {data:'data2'}]; | |
async.eachSeries(records, function (record, cb) { | |
// this was inside an angular project, but use whatever ajax call you want here | |
$http.post('http://myurltopost', record). | |
success(function (data, status, headers, config) { | |
cb(null, data); | |
}) | |
.error(function (data, status, headers, config) { | |
// called asynchronously if an error occurs | |
// or server returns response with an error status. | |
cb('error', null); | |
}); | |
} | |
, function (e) { | |
resolve(response); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment