http://qs321.pair.com?node_id=1172408


in reply to jQuery issue with Dancer2

Your aux_state() function doesn't return any value. In case you didn't realize, in javascript, 'return' isn't implied like it is in Perl. If that is what you thought, then you also might be assuming that the return value from .get() is the same as the return value from your success function? But I didn't see any mention of a return value from .get() when reading the documentation that I found by searching for jQuery .get.

If JavaScript didn't lack co-routines and so didn't force you into the fragmented code of call-back hell, then you could do something like:

function aux_state(aux){ var returned; $.get(host +'/get_aux/' + aux, function(state){ alert(state); // LINE 2 returned = state; }); return returned; }

And the nature of "call-back hell" infects all of the callers of your function so you probably just can't end up with something that would work for the code you wrote as:

var state = aux_state(­'aux1');

You likely have to have yet another call-back that would get the fetched state passed to it.

- tye