Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: jQuery issue with Dancer2

by stevieb (Canon)
on Sep 23, 2016 at 23:10 UTC ( #1172507=note: print w/replies, xml ) Need Help??


in reply to jQuery issue with Dancer2

Hey all, I admit that I was a bit under the influence when I posted this yesterday, and to those who may have been offended for it not being Perl related (rightfully so), I apologize. I normally am restrained in making such decisions, but I didn't.

However, because I started this, I'd like it to be concluded. My team lead at work who's very experienced in JS gave me some pointers (I was having issues finding good resources online that put it in a way I easily understood. He explained the whole "callback hell", and in some ways, try to avoid it. Although he gave much better suggestions and pointers than the following, it's what I came up with that I understand to go forward with hacking jquery for the amount I'll need.

I simply call the overarching function on page load, and let it naturally (well, as naturally as JS can be I suppose) handle the whole chain in order. Knowing how jquery/js passes things around, that made it a bit easier to understand.

$(function(){ for(i = 1; i < 4; i++){ var aux = 'aux'+ i; aux_state(aux); } }); function aux_state(aux){ $.get(host +'/get_aux/' + aux, function(state){ $('#'+ aux).switchbutton({ checked: parseInt(state), onChange: function(checked){ $.get(host +'/set_aux/'+ aux +'/'+ checked, functi +on(data){ // do perl stuff }); } }); }); }

Your Mother, because this is a hack job with web UI, my code is all over the map, as I'm just learning. You can find it here on my github. Because I was fudging, you actually have to install the thing (normal steps of installing apply with make), and install some prereqs:

sudo apt-get install sqlite3 cpanm Dancer2; cpanm Dancer2::Plugin::Database

Perhaps others (I haven't properly managed the dependencies while playing around). I then run the app with plackup -R lib,bin,public bin/app.pl, which runs it on port 5000.

Anyways, eventually, it'll be a one-page interface to my Raspberry Pi based indoor grow environment automation control system.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2022-05-26 18:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (93 votes). Check out past polls.

    Notices?