For example I have a function:
var f1 = function(arg) {
var a;
$.ajax({
...
success: function(data) {
a = f2(data);
//return a;
}
});
//return a;
}
var f3 = function() {
a = f1(arg);
}
How can I return a after AJAX get data in f1?
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
Then you’d call
f1like this: