I know I can pass the callback function to access the value,looks like How to return value from an asynchronous callback function? but in my case , It need execute the synchronous method so i can do action outside the callback,any tip to help?
var foo;
function getFoo(callback) {
$.ajax({
url: url,
async: false
})
.done(function(respond) {
var data = respond.data;
doStuff(data, function(respond) { //This is callback from Asynchronous function
callback(respond);
})
});
}
getFoo(function(respond) {
foo = respond;
});
return foo; //How can I access foo value from respond