title: How to check AJAX call is completed
body: <p>I have a page where I have to bind the few controls via ajax call.
  Country drop down, state drop down on the basis of selected country, city drop down on the basis of selected city. Nested data binding is working fine.</p>
  
  <p>But If I have some initial values of country, state, city &amp; I have to set the selected values, then this is not working. I am calling a function to set initial values like below:</p>
  
  <pre><code>function bindandsetvalues(_country, _state, _city){
  
    // function to bind countries via ajax call. ajax logic is inside this function
    bindcountries();
  
    if($("#country").length &gt; 0){
      // set selected country
      $("#country").val(_country);
  
      // function to bind states via ajax call. ajax logic is inside this function
      bindstates(_country);
  
      if($("#state").length &gt; 0){
        // set selected state
        $("#state").val(_state);
      }
    }
  }
  </code></pre>
  
  <p>But only country drop down is populated. Neither initial value of country sets nor state drop down binds.</p>
  
  <p>I have also found the reason.
  After calling bindcountries() function, control goes to the bindcountries() function. But there is a asynchronous ajax call inside bindcountries() function, so after calling the ajax call, control gets back to the caller function without waiting for the completion of ajax call where I called </p>
  
  <p>$("#country").val(_country);</p>
  
  <p>But because ajax async call is still in progress &amp; country drop down will be bind &amp; render after completing the ajax call.</p>
  
  <p>So, Neither initial value of country sets nor state drop down binds.
  So, My question is: Is there any way to check or wait for the completion of AJAX async call, so that I will check the existence of rendered control ($("#state").length > 0) after that that time/completing ajax call.</p>
  
  <p>I know there is are .done, .fail &amp; .always methods of jquery ajax where I can handle post ajax call logic. But in my above case, I can't use those methods. &amp; there are more than eight this type of nested controls which I have to set.</p>
  
  <p>Please suggest me a solution.</p>