title: How to figure out whether an AJAX call in a function returns an error or succeeds?
body: <p>How would I detect whether an AJAX call in a function succeeds or fails? Let's say I call that function elsewhere.</p>
  
  <p><strong>file.js</strong></p>
  
  <pre><code>function doSmallThing(param1, param2) {
  
   $.ajax({
     type: 'post',
     url: 'some_url',
     dataType: 'json',
     ...
     success: function (result) {
  
       // doStuff, signal that this code block is reached
  
     },
  
     error: function (error) {
       // signal that this is reached
     }
  
   })
  
  }
  </code></pre>
  
  <p><strong>file2.js</strong></p>
  
  <pre><code>import File from "..location/of/file.js";
  
  class SomeComponent extends React.Component {
  
    doSomething() {
  
      // stuck here
  
      if (File.doSmallThing(param1, param2) does not throw an error) {
         doMoreThings();
      } else {
         // do nothing
      }
  
  
  
    }
  
  }
  </code></pre>
  
  <p>How would I detect the outcome of:</p>
  
  <pre><code>File.doSmallThing(param1, param2)
  </code></pre>
  
  <p>Please help. Thanks.</p>