title: jQuery - Wait for a function to return value
body: <p>I have a jquery function for sending email with ajax request;</p>
  
  <pre><code>function sendMail(from,to,subject,message){
      var datastr="from="+from+"&amp;to="+to+"&amp;subject="+subject+"&amp;message="+message;
      $.ajax({
          type: "POST",
          url: "mail.php",
          data: datastr,
          cache: false,
          success: function(html){
              return true;
          },
          error: function(jqXHR,status,error){
              return false;
          }
      });
  }
  </code></pre>
  
  <p>now I want to tell the user if the mail was successfully sent or not like this:</p>
  
  <pre><code>$("#feedback").html("Sending email...");
  if(sendMail("from@email.com","to@email.com","MySubject","MyMessage"))
     $("#feedback").html("Email sent.");
  else
     $("#feedback").html("Error sending email.");
  </code></pre>
  
  <p>but of course jQuery processes the if condition before the mail was sent, so the condition is false :-(
  How do I tell jQuery to wait until sendMail has completed and returns something?</p>