JSFiddle - React, Tailwind, and code Playground
JavaScript
const urls = [
'https://dewnuf111111.com/configuration',
'https://dewnuf222222.com/configuration',
'https://bcsmania.co.uk/test.json'
];
let obj = {a: 'test'};
let counter = 0;
function ajax(url) {
// Check for for last URL in the array
if (counter < urls.length) {
return fetch(url)
.then(response => {
// Combine objects
obj = Object.assign(obj, response.json());
console.log(urls[counter], obj);
return Promise.resolve(obj);
}).catch(error => {
counter++;
// Fetch next URL
ajax(urls[counter]);
});
}
}
function getConfigurations() {
return ajax(urls[counter]);
}
getConfigurations().then((configurations) => {
console.log('DONE', configurations);
});