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

Re: jQuery issue with Dancer2

by Corion (Patriarch)
on Sep 23, 2016 at 05:24 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-25 23:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found