IN JQUERY, HOW DO I RETURN THE RESPONSE FROM AN ASYNCHRONOUS CALL?

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);

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>