For example
function getResult(field) {
$.ajaxSetup ({cache: false, async: false});
$.get("api.php?field="+field, function(i) {
result = i;
});
return result;
};
The problem with this is that result becomes global. If I do var result = i; then the parent function (getResult) cannot see the variable result.
Is there a clever way to do this?
The code that I have posted works correctly. I have set my AJAX calls to be done synchronously.
Generally what you want to do is create a local variable in the outer function that the inner function manipulates through closure scope