title: How do I chain three asynchronous calls using jQuery promises?
body: <p>I have three HTTP calls that need I need to make in a synchronous manner and how do I pass data from one call to the other?</p>
  
  <pre><code>function first()
  {
     ajax()
  }
  
  function second()
  {
     ajax()
  }
  
  function third()
  {
     ajax()
  }
  
  
  function main()
  {
      first().then(second).then(third)
  }
  </code></pre>
  
  <p>I tried to use the deferred for the two functions and I came up with a partial solution. Can I extend  it to be for three functions?</p>
  
  <pre><code>function first() {
      var deferred = $.Deferred();
       $.ajax({
  
               "success": function (resp)
               {
  
                   deferred.resolve(resp);
               },
  
           });
      return deferred.promise();
  }
  
  function second(foo) {
       $.ajax({
              "success": function (resp)
              {
              },
              "error": function (resp)
              {
              }
          });
  }
  
  
  first().then(function(foo){second(foo)})
  </code></pre>