You can’t return the result of your ajax request since the request is asynchronous (and synchronous ajax requests are a terrible idea).
Your best bet will be to pass your own callback into f1
var f1 = function(arg, callback) {
$.ajax({
success: function(data) {
callback(data);
}
});
}
Then you’d call f1
like this:
f1(arg, function(data) {
var a = f2(data);
alert(a);
}
);