title: AJAX return true/false - I have implemented a callback
body: <p>First of all I have read these topics:</p>
  <ul>
  <li><a href="https://stackoverflow.com/questions/20282538/jquery-ajax-function-return-true-or-false-returning-only-false-while-its-all-goo">jQuery AJAX function return true or false returning only false while its all good</a></li>
  <li><a href="https://stackoverflow.com/questions/15887595/what-to-return-for-jquerys-ajax-data-param-in-callback-function">What to return for jQuery&#39;s ajax data param in callback function?</a></li>
  <li><a href="https://stackoverflow.com/questions/19345302/how-return-true-or-false-function-of-data-response-ajax">How return true or false function of data response ajax?</a></li>
  </ul>
  <p>and I still cannot figure out how to get this to work.</p>
  <pre><code>$(&quot;#btn_go&quot;).on('click', function(){
      if(validateUserDetails() == false){ 
          return;
      }
  });
  </code></pre>
  <p>The function <code>validateUserDetails</code> has the following:</p>
  <pre><code>function validateUserDetails(){
      var bool = false;
      
      $.ajax({
          url: 'response.php?type=validateUserDetails',
          type: 'POST',
          dataType: 'json',
          data: {
              name: $(&quot;#checkout_name&quot;).val(),
              email: $(&quot;#checkout_email&quot;).val(),
              &quot;country&quot;: $(&quot;#checkout_country&quot;).val(),
              &quot;city&quot;: $(&quot;#checkout_city&quot;).val()
          },
          success: function(data){
              console.log(data); // this is currently returning FALSE
                                 // Which is totally correct!
              if(data == true){ bool = true; }
              return trueOrFalse(bool);
          }
      });
  }
  
  function trueOrFalse(bool){
      return bool;
  }
  </code></pre>
  <p>However, this is not working because if I output the function I get <code>undefined</code>, which means that the function is not retuning the correct value. <code>console.log(validateUserDetails()); // = undefined</code></p>
  <p>What am I doing wrong?</p>