title: Recursively call an ajax function until the first ajax function is completed
body: <p>I have a python file which appends a result into log file and I need to print this log synchronously in UI.</p>
  
  <p>Following is my code</p>
  
  <pre><code>var flag = 0;
  function write_log_in_file(){
    var settings = {
      "async": true,
      "crossDomain": true,
      "url": "http://localhost/build5/builds/test.py",
      "method": "POST",
      "headers": {
        "cache-control": "no-cache"
      }
    }
    $.ajax(settings).done(function (response) {
      flag =1;
      console.log(response);
    });
  };
  
  function get_log_from_file(){
    var settings = {
      "async": true,
      "crossDomain": true,
      "url": "http://localhost/build5/builds/build.log",
      "method": "GET",
      "headers": {
        "cache-control": "no-cache"
      }
    }
    $.ajax(settings).done(function (response) {
      console.log(response);
    });
  };
  
  //Write build log in build.log file
  write_log_in_file();
  
  //Get log until python call is completed 
  while(!flag){
    get_log_from_file();
  }
  </code></pre>
  
  <p>Here, I have used flag variable, which is set to 1 after my first ajax call is completed. Until then my second ajax call is being called recursively.</p>
  
  <p>Since I have used while, flag variable never becomes 1 and while goes in infinite loop. </p>
  
  <p>Is there any other method, where I can recursively call my ajax function, while other ajax function is completed?</p>