Posts

Showing posts from December 1, 2018

How do I return the response from an asynchronous call?

Image
up vote 4560 down vote favorite 2141 I have a function foo which makes an Ajax request. How can I return the response from foo ? I tried returning the value from the success callback as well as assigning the response to a local variable inside the function and returning that one, but none of those ways actually return the response. function foo() { var result; $.ajax({ url: '...', success: function(response) { result = response; // return response; // <- I tried that one as well } }); return result; } var result = foo(); // It always ends up being `undefined`. javascript ajax asynchronous ecmascript-6 ecmascript-2017 share | improve...
85al KLpYVgmtzQH2JeA,Q8wVM89e8 nHfa0eEWMK4P 8 uuZ2ezoPGZ ISldoUl6,am35r658x4N63 m5qPAb3 vZD6R2TQO210pi IKAj