How do I return the result of the nested ajax call as the result of the parent function?
//Declaring the function
var myFunction = function(myData){
$.ajax({
type:'post',
url:"/ajaxPage.php",
data:{data:myData},
success:function(r){
return r;
});
}
//Calling the function
var theResult = myFunction(myData);
I want the variable ‘theResult’ to hold the contents of the ajax call.
You will have to make your AJAX call synchronous (not asynchronous which is the default).
Something like this: