jQuery: How do you perform a callback inside an AJAX call
<p>I have a function with an AJAX call inside it, I need to be able to call the function and it return true if the AJAX request was successful and false if not.</p>

<p>I know the following doesn't work because the returns are out of scope to the exampleFunc()</p>

<pre><code>function exampleFunc() {
  $.ajax({
    url: 'http://example.com/page',
    success: function(data, textStatus, XMLHttpRequest){
      return true;
    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {
      return false;
    }
  });
}
</code></pre>

<p>I Googled for a solution and believe I should be doing a callback but couldn't seems to achieve the desired outcome.</p>

<p><strong>Edit:</strong> Te be more specific I require the function to return true or false because my use case currently has me doing :</p>

<pre><code>if (exampleFunc()) { 
  // run this code
}
</code></pre>
