I have a javascript code, and at a certain point, i want to pause the execution till an ajax communication is done before continuing.
I have the following
var set_ajax_done = function(){
ajax_done = true;
}
// Ajax part
ajax_done = false;
$.ajax({
url: $url,
type: 'GET',
success: function (result) {
// some treatment
set_ajax_done();
}
});
// Make sure the ajax communication and treatment are done before continuing
make_sure_aj_comm_finished();
var make_sure_aj_comm_finished = function(){
if ( ajax_done == false )
{
setTimeout(function(){
make_sure_aj_comm_finished();
}, 500);
}
}
When i execute this code, it seems that the execuion just goes through and does not wait for the boolean variable ajax_done to true.
How could i make the code to execute make_sure_aj_comm_finished
recursively till the variable ajax_done is true
Thanks!