I have some code that does this:
function A(){
$.ajax({
...blah blah...
success: function(data){
return data;
});
}
and then I’m trying to use the data later:
var x = A();
x.doSomething();
but x is never stored, since A() takes a while. Is there any way to avoid this?
Other Questions about the same topic:
I’m sure there are more. However the advice in all of them will boil down to two paths to take.
Pass a callback down the line
Making your AJAX Synchronous
This option seems easier, but it will also block all script execution while it waits for your AJAX request, and therefore is not as desireable