title: If statement based on AJax return
body: <p>i have an easy Ajax request who return true or false according to the result, like this :</p>
  
  <pre><code>function myRequest(){
      $.ajax({
           url: "/",
           method: "GET",
           contentType: "application/json",
           dataType: 'json',
      }).done(function (data) {
           if (data['code'] !== "success") {
                return false;
           }
           else {
                return true;
  
      }}).fail(function (xhr, textStatus, errorThrown) {
                return false;
      });
  }
  
  if(myRequest()){
  //do someting
  }
  </code></pre>
  
  <p>When myRequest() is executed for the if statement, it's doesn't wait the Ajax result and is never validate. 
  I read about promise here and i tried but it still the same issue. </p>
  
  <p>Ty !</p>
  
  <p>[EDIT]</p>
  
  <p>So i follow your replies and i just retry with promises. It's work better :</p>
  
  <pre><code>function myRequest(){
     return new Promise((resolve, reject) =&gt;{
          $.ajax({
               url: "/",
               method: "GET",
               contentType: "application/json",
               dataType: 'json',
          }).done(function (data) {
               if (data['code'] !== "success") {
                    resolve(false);
               }
               else {
                    resolve(true);
  
          }}).fail(function (xhr, textStatus, errorThrown) {
                    rejected(errorThrown);
          });
        });
      }
  
  myRequest().then(function (val) {
      if(val){
         return true;
      }
  });
  </code></pre>