Recently I asked this question:
Moderator Sergio helped me with the issue, but I'm still having issues with compatibility with legacy browsers. Is there a way to accomplish this without using Promises and running on older browsers?
Here is the example code:
function getNome(nome) {
const url = 'https://httpbin.org/get?nome=' + nome;
return new Promise((resolve, reject) => {
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.onload = function() {
if (xhr.status === 200) resolve(JSON.parse(xhr.responseText));
else reject(xhr.status);
};
xhr.send();
});
}
const nomes = ["lucas", "pedro", "joao"];
Promise.all(nomes.map(getNome)).then(res => {
console.log(res);
});
What I want is to go through an array, and perform a request on each name and save the response on an object, meanwhile the code keeps on running and doing other tasks, when all the answers are in an object the code fires another function.