title: Sequential function calls in javascript
body: <p>I want function A to finish execution and only after that function B should start executing. When I call function A and then function B, it seems both are executing simultaneously. And after function B completes, I want to call a third function update_dropdown(). </p>
  
  <p>My code looks like this:</p>
  
  <pre><code>function A {
      for (var i = 0; i &lt; 5; i++) {
          var promise = $.get(url+i);
          $.when(promise).then(function () {
              $.post(url);
          });
      }
  }
  function B {
      var x = $.get(url);
      var promise = $.post(url+x);
      $.when(promise0).then(function () {
          update_dropdown();
      });
  }
  </code></pre>
  
  <p>Please can you tell me how I can make these 3 function calls happen sequentially. </p>