Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: jQuery issue with Dancer2

by Corion (Patriarch)
on Sep 23, 2016 at 05:24 UTC ( #1172404=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1172404]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2022-05-28 15:01 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (99 votes). Check out past polls.