I have the following code.
var foo = {
ajaxcall : function(){
var _obj = {};
$.ajax({
headers: {
'Content-Type': "application/json; charset=utf-8",
'dataType': "json"
},
async: false,
url: "/getservertime"
}).done(function(resp,stat) {
resp = JSON.parse(resp);
_obj.resp = resp;
console.log(_obj);
return _obj;
});
},
init: function(){
this.somefunction(this.ajaxcall());
},
somefunction: function(_data){
console.log(_data); // coming as undefined
}
}
foo.init();
How can I wait for execution of ajax to complete and then execute somefunction
method. I have already tried async: false
. Looks like some other issue.