title: ajax call inside .each of another ajax call's success function - jQuery
body: <p>I have an ajax call that returns data with a lat and long in it.</p>
  
  <pre><code>$.ajax(
  {   
    url: 'json/data.json',
    dataType : 'json',
    type: 'get',
    cache: false,
    success: function(fullJSONData)
    {
      $(fullJSONData.events).each(function(index, oneJSONLine)
      {
          $('#eventList').append(newEvent(index, oneJSONLine))            
      });
    },
    error: function (e) 
    {
      console.log("error " + e.message);
    }
  
  });
  </code></pre>
  
  <p>I am looping through using .each and here with the newEvent function I am calling another ajax request to reverse geocode the lat and the long.</p>
  
  <pre><code>function newEvent(iter, event)
  {   
    var placeName
  
    getGeoCode(event.lat, event.long, function(returnAddress)
    {
      placeName = returnAddress
      //other processing
    }
  }
  
  
  function getGeoCode(lat, long, callback)
  {
     var newurl = "https://maps.googleapis.com/maps/api/geocode/json?latlng="
     newurl += lat
     newurl += ',' 
     newurl += long 
     newurl += '&amp;key=AIzaSyCgISQV9F_6VW_wqyJk9rM5rTWvoD_eqVs'
  
  $.ajax(
  {
      //GeoCode Api       
      url: newurl,
      dataType : 'json',
      type: 'get',
      cache: false,
      success: function(fullJSONData)
      {
          callback(fullJSONData.results[0].formatted_address)     
      },
      error: function (e) 
      {
          console.log("error " + e.message);
      }
  
  });
  </code></pre>
  
  <p>I think I understand what is happening but I am at a bit of a loss as to how to solve it.  I believe the .each is not waiting for the ajax inside it to complete as I would imagine would happen since it's ajax.  Can I force the .each to wait until each internal ajax call is completed before continuing?  I have tried <code>async:false</code> but I'm getting a deprication error saying that it is not good on the main thread. </p>
  
  <p>Can anyone point me in the right direction?  I just about got the callback function working for the second ajax call, and have tried putting one around the first ajax call  but it's a little beyond me.</p>
  
  <p>Thanks</p>