Quantcast
Channel: How do I return the response from an asynchronous call? - Stack Overflow
Viewing all articles
Browse latest Browse all 46

Answer by Hemant Bavle for How do I return the response from an asynchronous call?

$
0
0

The simplest solution is to create a JavaScript function and call it for the Ajax success callback.

function callServerAsync(){    $.ajax({        url: '...',        success: function(response) {            successCallback(response);        }    });}function successCallback(responseObj){    // Do something like read the response and show data    alert(JSON.stringify(responseObj)); // Only applicable to a JSON response}function foo(callback) {    $.ajax({        url: '...',        success: function(response) {           return callback(null, response);        }    });}var result = foo(function(err, result){          if (!err)           console.log(result);});

Viewing all articles
Browse latest Browse all 46

Trending Articles



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