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.


In reply to Re: jQuery issue with Dancer2 by stevieb
in thread jQuery issue with Dancer2 by stevieb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.