Quantcast
Viewing latest article 19
Browse Latest Browse All 44

Answer by Khoa Bui for How do I return the response from an asynchronous call?

Of course there are many approaches like synchronous request, promise, but from my experience I think you should use the callback approach. It's natural to asynchronous behavior of JavaScript.

So, your code snippet can be rewritten to be a little different:

function foo() {    var result;    $.ajax({        url: '...',        success: function(response) {            myCallback(response);        }    });    return result;}function myCallback(response) {    // Does something.}

Viewing latest article 19
Browse Latest Browse All 44

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>