I'm trying to get the data from one or multiple sources, so I pass in an array of urls to get the data from and make a promise.
Then I try to use Promise.all
in order to get all the data, but I don't get anything at all.
How can I solve this?
var getData = function (urls) {
var promises = [];
$.each(urls, function (index, url) {
var promise = new Promise(function (resolve, reject) {
$.ajax({
type: 'get',
url: url,
dataType: 'json',
success: function (data) {
console.log(data);
}
});
});
promises.push(promise);
});
console.log(promises);
Promise.all(promises).then(function () {
console.log('Complete');
});
};