title: How to make code wait while calling asynchronous calls like Ajax with returned value
body: <p>I've read a lot of question about this topic. But nobody has my problem.
  Actualy I have this in my main code:  </p>
  
  <pre><code> // getHtmlInfoWindows has inside an ajax request
   var infowindowString = getHtmlInfoWindow(selectedTrucks[i], true);
   makeInfoWindowEvent(map, infowindow[i], infowindowString, markers[i], "click");
  </code></pre>
  
  <p>Here the getHtmlInfoWindows() code</p>
  
  <pre><code> $.ajax({
      url: ajaxUrl,
  })
  .done(function(data) {
       // some line of code and operation
       return someData;
  }
  </code></pre>
  
  <p>Basically I would to wait until getHtmlInfoWindow() finish and next execute makeInfoWindowEvent() but I don't know how. </p>
  
  <p>I've tried this:</p>
  
  <pre><code> $.when(infowindowString = getHtmlInfoWindow(selectedTrucks[i], true)).done(function(){}
  </code></pre>
  
  <p>but doen't work because a have to return the intere ajax response and not the single value "someData" that I want.
  How can I do? </p>
  
  <p>Thanks guys</p>