It seems you need to make ajax synchronous call. You can do it like this:
$.ajax({ ... async: false, success: ... }); return a;
Thus, JS execution is paused until the call returns and the success
function is executed.
Of course, there is a problem with synchronization calls. It is best to reorganize your code so that you do what you need to do with the variable a
in the success
callback.
Based on this idea, suppose your f3
function was something like this:
var f3 = function() { a = f1(arg); alert(a);
Instead, you can do this:
var f3 = function() { f1(arg); } var f3_callback = function(a) { alert(a);
So your success function will look like this:
success: function(data) { a = f2(data); f3_callback(a); }
Hope this is clear!
cambraca
source share