Alex Rivera | Logout

return AJAX callback return

Asked 2012-01-27T23:13:15.573
8

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?

Edit
Report

1 Answer

-1

The easiest way to do this is to make the ajax call synchronous. Meaning in your f1 function setup the ajax call with async: false so that the function doesn't move on until the call is completed and the data returned.

answered 2012-01-27T23:17:38.337

Your Answer