In JQuery, How do I return the response from an asynchronous call?
You can return the response from an Async call in two ways:
1)using callback
ajax(“/echo/json”).then(function(result) {.. }
2) promise
function foo(callback) {
$.ajax({…success: callback(result)
});
}
function myCallback(result) {
// Code that depends on ‘result’
};
foo(myCallback);