Consider:
function ajaxCall(url, callback) {
$.ajax({
type: "GET",
url: url,
success: function (data) { // <-- fail point: where does the returned data go, now?
// do stuff with data
if ( callback ) {
var ret = callback();
if ( ret !== undefined ) {
return ret;
}
}
}
});
}
function fooBar() {
return ajaxCall('some/url', function () {
// do stuff
return some_value;
}
}
Right, so basically, I want to preserve the asynchronousness of the request so the browser doesn't hang, but still return a value in the end... This is a simplified example, even though I could probably simplify it even more.
In fact, the only obstacle I see is the transition between $.ajax
and its success:
anonymous function.
Hmph.