I have a function foo which makes an Ajax request. How can I return the response from foo
?
I tried to return the value from the success callback as well as assigning the response to a local variable inside the function and return that one, but none of those ways actually return the response.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
function foo() { var result; $.ajax({ url: '...', success: function(response) { result = response; // return response; // <- tried that one as well } }); return result; } var result = foo(); // always ends up being `undefined`. |
Continue reading “How to return the response from an asynchronous call?”