Recursively call an an ajax function until the first ajax function is completed

I have a python file which appends a result into log file and I need to print this log synchronously in UI.

Following is my 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();
}

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.

Since I have used while, flag variable never becomes 1 and while goes in infinite loop.

Is there any other method, where I can recursively call my ajax function, while other ajax function is completed?

JavaScript         JQuery         Ajax         parallel-processing        
Your Answer: 

0 Answers
Edit Account
LOGIN INFORMATION
Change Settings
Email Notifications Notifications will be sent to abcd@gmail.com
Select option for your email notifications:
Mature / News Filter We'll send on email when new jobs are posted
Option 2 for email notification We'll send on email when new jobs are posted