How to catch wrong URL in JavaScript?
<p>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&amp;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.</p>

<pre><code>let found = null;
try {
  $.ajax({ url: mainUrl })
    .done(function (a) { found = true; });
} catch (e) { 
  found = false;
}
</code></pre>

<p>In the console, I can see the browser whine about not being able to find the source <strong>but</strong> the testing variable <code>found</code> is still <code>null</code>. What am I missing?</p>

<p>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.</p>