title: Ajax calling order within multiple functions
body: <p>In the following code, I want the alerts to come in order (1st call followed by the second), but it keeps coming the other way around. This is causing some variables to become undefined. What is the order of execution when having multiple ajax queries in the same code? How can I change the order of the alerts?</p>
  
  <pre><code>$(document).ready(function () {
  
    function get_det() {
      $.ajax({
        url: "aa.php",
        type: "POST",
        success: function (result) {
          alert("1st call");
        }
      });
    }
  
    $.ajax({
      type: "POST",
      contentType: "application/json",
      url: "dd.php",
      success: function (result) {
        initializeMap();
      }
    });
  
  
    function initializeMap() {
      //other code
      calculateAndDisplayRoute();
      //other code
  
      function calculateAndDisplayRoute() {
        //other code
        get_det();
        alert("2nd call");
        //other code
      }
  
    }
  
  });
  </code></pre>