title: Waiting on asynchronous call not working with ajax
body: <p>I used deferred to wait about two function to complete (they feed template and display the result) before feeding a select present in the template.</p>
  
  <p>When a tab is displayed, i do.</p>
  
  <pre><code>var notAssociateContact = getNotAssociateContact();
  var associateContact = getAssociateContact();
  
  $.when(notAssociateContact, associateContact).then(assignLocationToSelector($("select[name=locationIds\\[\\]]")));
  
  function getNotAssociateContact() {
  
      var deferred = $.ajax({
          type: "GET",
          url: "http://localhost:8080/rest/contacts/notassociatedto/" + $("#lodgerId").val(),
          success: function(data, status, jqXHR) {
  
              $("#lodgerContactAvailableDivTemplate").empty();
              if (data.length != 0) {
                 $("#lodgerContactAvailableDivTemplate").append(templateLodgerContactAvailable(data));
                  $('#lodgerContactAvailableTableResult').bootstrapTable();
              }
          },
          error: function(jqXHR, status) {
              // error handler
              alert("error " + jqXHR + " -  " + status);
          }
      }).then(function(response) {
          // optional callback to handle this response 
      });
      return deferred;
  
  }
  
  
  function getAssociateContact() {
      var deferred = $.ajax({
          type: "GET",
          url: "http://localhost:8080/rest/lodgers/" + $("#lodgerId").val() + "/contacts",
          success: function(data, status, jqXHR) {
              $("#lodgerContactDivTemplate").empty();
              if (data.length != 0) {
                  $("#lodgerContactDivTemplate").append(templateLodgerContact(data));
                  $('#lodgerContactTableResult').bootstrapTable();
                  //  $('#lodgerContactTableResult tr').bind("dblclick", null, contactReferenceSelectedRow);
              }
          },
          error: function(jqXHR, status) {
              // error handler
              alert("error " + jqXHR + " -  " + status);
          }
      }).then(function(response) {
          // optional callback to handle this response 
      });
      return deferred;
  }
  </code></pre>
  
  <p>I don't get any error, but the assignLocationToSelector don't same to runned.
  Select is empty.</p>
  
  <p>In console if i run</p>
  
  <pre><code>assignLocationToSelector($("select[name=locationIds\\[\\]]"));
  </code></pre>
  
  <p>Select is feeded correctly.</p>
  
  <p>When i debug and arrive on $.when, i see then the two ajax call is pending...</p>
  
  <p>So it's seem like there is a issue with the deferred.</p>