JSFiddle - React, Tailwind, and code Playground
by Dogbert
JavaScript
function tryGet(urls, done, fail) {
if (urls.length == 0) {
fail();
} else {
$.get(urls[0])
.done(done)
.fail(function() {
tryGet(urls.slice(1), done, fail);
});
}
}
tryGet(["http://Url1.com", "http://Url2.com", "http://Url3.com"], function(_, _, resp) {
console.log(resp.status);
}, function() {
console.log("all failed");
});
tryGet(["http://Url1.com", "http://Url2.com", "http://Url3.com", "/"], function(_, _, resp) {
console.log(resp.status);
}, function() {
console.log("all failed");
});