title: How to check if an api call has completed
body: <p>I have a script in my code </p>
  
  <pre><code>&lt;script src="https://geodata.solutions/includes/statecity.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>which is making an ajax call. This script is used to fetch states and cities and loads the value in select. How do I check whether that particular call is complete as it is in this external script and I want to set value of select using javascript/jquery</p>
  
  <p>I am currently using setTimeout for setting select value and delaying it randomly for 6 seconds however it's not the right approach. Also, I have tried putting the code to set value in $(document).ready() but the api call returns the values later</p>
  
  <pre><code>        setTimeout(function(){ 
          jQuery("#stateId").val('&lt;?php echo $rowaddress['state']; ?&gt;').change();
          setTimeout(function(){ 
              jQuery("#cityId").val('&lt;?php echo $rowaddress['city']; ?&gt;').change();
          }, 3000);
      }, 6000);
  </code></pre>