You need to restructure your code. The anonymous function inside .done()
is executed after functionAAA
has already completed and returned undefined
. AJAX calls are Asynchronous, after all.
$.ajax
returns a promise
, so one option is to use .then()
:
function functionAAA(){
return $.ajax({
url: 'http://jsfiddle.net/echo/jsonp/',
dataType: 'jsonp',
});
}
functionAAA().then(function() {
alert("111111111");
if (functionBBB()){
alert("2222222");
if (functionCCC()){
alert("333333333333");
}
}
});
see it in action on JSFiddle.