The function below first performs a synchronous comparison test == 0
, and if it passes, returns some content, and if it doesn't pass, performs an asynchronous request. My intent is for the later to return some other content such as "something from post callback", but know I am doing things way wrong. Without changing the Ajax request to synchronous, is it possible to do this?
var value = function (test) {
if (test == 0) {
return 'value is zero ';
} else {
return $.post('/echo/html/', {
html: 'false ',
delay: .5
}, function (r1) {
console.log('r1', r1);
return 'something from post callback';
})
.done(function (r2) {
console.log('r2', r2);
return 'something from done callback';
});
}
}(1);
console.log(value);