I have two callbacks one of them should return boolean value and other do an ajax call. but can't get result from the second one.
I've read some explanation of how to return the response from an asynchronous call but can't get any result.
there is my code :
if( $.fn.wizard ) {
$('#wzd-enrollment').wizard({
//some code
onStepLeave: function (wizard, step){
//in this function i have always to return a boolean value to move to the next step or not
var result;
result = doAjax(wizard, step);
console.log(result); //always log undefined
return result;
}
});
function doAjax(wizard, step){
if(step.id == 'step-1' ){
//some code
$.ajax({
type: "GET",
dataType: 'json',
url: s_url,
}).done(function( data ) {
//some code
return true;
}).fail(function(jqXHR, textStatus, errorThrown){
//some code
return false;
});
}else{
return true;
}
}
}