title: Wait for ajax request inside a function : $.Deferred ? $.When ? jQuery
body: <p><strong>How to wait until the ajax is done inside a deferred function ? Example :</strong> </p>
  
  <pre><code>    function action() {
          console.log('action is called');
  
          var deferred = $.Deferred();
  
          console.log('do some actions...');
  
          //Wait until the ajax is completed and continue script
          var myAjaxCall = ajaxCall();
  
          //Execute te next scripts only after the ajax done
  
          console.log('do some actions...');
  
          return deferred.promise();
      }
  
  
      function ajaxCall() {
          console.log('ajaxCall is called');
  
          return $.ajax('url').then(function() {
              console.log('success  ajaxCall');
          });
      }
  
      action().then(function () {
          console.log('after action is done and ajaxCall is done');
      });
  </code></pre>
  
  <p>The probleme is that he function must wait until the ajax inside is called and done and continue other scripts.</p>
  
  <p>Thank you.</p>