Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: jQuery issue with Dancer2 (return)

by tye (Sage)
on Sep 23, 2016 at 05:39 UTC ( #1172408=note: print w/replies, xml ) Need Help??

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        

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2022-09-29 14:34 GMT
Find Nodes?
    Voting Booth?
    I prefer my indexes to start at:

    Results (125 votes). Check out past polls.