http://qs1969.pair.com?node_id=1172404


in reply to jQuery issue with Dancer2

This has nothing (nothing!) to do with Perl at all.

If you eliminate the $.get call and replace it by something else that calls your callback, you will see exactly the same.

Your aux_state function never returns a value, because it doesn't have a return statement:

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

The return statement you see is for the callback function that gets invoked asynchronously by jQuery. The aux_state function returns immediately and returns no value.

To capture the return value of your $.get() call asynchronously in Javascript, you will have to pass in another callback to aux_state which then gets invoked once the value is available. This is what people name Callback Hell.