I need to fetch data from the main service but sometimes, it's not working and I wanted to have a fallback. The idea of a Q&D solution was to download some data from it and if it fails, catch the error and change the URL to a local one. Like this.
let found = null;
try {
$.ajax({ url: mainUrl })
.done(function (a) { found = true; });
} catch (e) {
found = false;
}
In the console, I can see the browser whine about not being able to find the source but the testing variable found
is still null
. What am I missing?
If there's a better (but still fairly simple) way to detect the presence of the web services? If so, I'm open to suggestions. But mainly, I'm curious what's wrong with the sample above.