How I call methods in my page using sync methods (wait for the answer of each one) ?
I did tests with async : false to test, but its not work in jQuery current version.
function mainAction()
{
if (!action1())
{
console.log('error : action1');
return false;
}
if (!action2())
{
console.log('error : action2');
return false;
}
console.log('done');
return true;
}
And the basic structure in each function that I call:
function action2()
{
$.ajax({
type: "GET",
url: someurl...,
dataType: "html",
timeout: 30000,
data:
{
//somedata...
},
success: function(data)
{
response = $.parseJSON(data);
return (response.status == 'ok');
},
error: function (jqXHR, textStatus, errorThrown)
{
console.error(textStatus + ' ' + errorThrown);
return false;
},
complete: function(jqXHR, textStatus)
{
}
});
}
The return on each statement (success/complete/error) not affect the return of the entire function, what I need to force the return (boolean) of the function after the ajax finish ?