My dilemma involves returning a callback value outside of the callback function. Here's an example:
I created this function based on the topic discussed in: How do I return the response from an asynchronous call?
(function (){
return getAjaxResult(function(result) { return result; });
//<-- Return Undefined (in console log return correct value)
})();
function getAjaxResult(callback){
$.ajax({
url: 'myurl',
type: 'GET',
success: function (result)
{
if (result === 'working'){
callback(result);
}else if (result === 'notworking'){
callback('notworking');
}
}
})
}
It returns "Undefined" (even though the console log shows the correct value).
I'm unsure if this is the most efficient way to return an ajax value in a callback function.