From: David N. <dno...@ya...> - 2011-05-11 18:26:40
|
Ryan, Have you looked at the xml server in mh/lib/xml_server.pl? I think it would be good to add a format=json option to it. I have some ideas on how to create a streaming or chunked server. David On 5/11/2011 6:54 AM, Douglas Parrish wrote: > Aesome!!! > > On Wed, May 11, 2011 at 6:56 AM, Ryan Davies > <ry...@pr... <mailto:ry...@pr...>> wrote: > > Hi All, > > > I have written a small prototype JSON server for dynamically > passing variables to web-pages using AJAX and JSON formatting. > > > My end goal is to completely re-work the WEB-UI into something a > little more WEB2.0 (I hate frames with a passion) > > > The work I have so far is this: > > > Objcts can be requested on the URL: > > E.g. I want the Time_Now and Time_Sunset variables: > /bin/variables.js.pl?Time_Now=&Time_Sunset= > <http://variables.js.pl?Time_Now=&Time_Sunset=> > > - Returns: > > {"Time_Now":"11:34 PM","Time_Sunset":"5:17 PM"} > > > If I want an entire Hash: > > /bin/variables.js.pl?Save= <http://variables.js.pl?Save=> > > - Returns: > > {"Save":{"web_hits_hour":0,"mode":"mute","web_count_default":1130,"ping_test_results":"up","sleeping_kids":0,"photo_index":null,"mhdl_date":"12/01/2008","mp3_Genre":null,"web_clients_hour":0,"Time_Saved":"11/05/11 > 23:35:00","web_hits_day":96,"mhdl_maj":2,"email_flag":" > 37","mp3_search":null,"web_clients_day":4,"trivia.Entertainment.cnt":23,"photo_search":null,"trivia.Science.cnt":21,"trivia.Sports.cnt":14,"trivia.Mixed.cnt":12,"security":null,"mh_exit":"abend","mhdl_min":105,"sleeping_parents":0}} > > > Or if I only want certain variables of that hash, e.g. just the > house mode and who is sleeping: > > /bin/variables.js.pl?Save=mode,sleeping_parents,sleeping_kids > <http://variables.js.pl?Save=mode,sleeping_parents,sleeping_kids> > > - Returns: > > {"Save":{"mode":"mute","sleeping_kids":0,"sleeping_parents":0}} > > An example of multiple hashes and variables: > > /bin/variables.js.pl?config_parms=html_dir&Time_Sunrise=&Weather=Summary_Short&Date_Now=&Tk_objects=label_cpu_used,label_memory_used > <http://variables.js.pl?config_parms=html_dir&Time_Sunrise=&Weather=Summary_Short&Date_Now=&Tk_objects=label_cpu_used,label_memory_used> > > - Returns: > > {"Time_Sunrise":"7:18 > AM","config_parms":{"html_dir":"/home/ryan/mh/web"},"Date_Now":"Wed, > May 11","Weather":{"Summary_Short":"19.0°C > 100%"},"Tk_objects":{"label_memory_used":"MB > 44.7/33.8","label_cpu_used":"CPU 6.0%"}} > > > Unfortunatly I dont have this working with objects at this stage > (Just builtin and overridden vars) > > > The plan is to have a UI that certain aspects can update via ajax > without having to pull large files, Also, each "section" can just > pull the data it needs. > > > Here is an example of a webpage calling this JSONgen via AJAX: > > <html> > > <head> > > <script type="text/javascript" src="js/jquery.min.js"></script> > > <script> > > function ajaxCallBack(data) { > > // Updated the required Classes > > // Called from fireJSON's getJSON > > // This function could also just store them in JS vars. > > $(".time_now").html(data.Time_Now); > > $(".cpu").html(data.Tk_objects.label_cpu_used); > > $(".mem").html(data.Tk_objects.label_memory_used); > > } > > $(document).ready(function() { > > fireJSON(); > > }); > > function fireJSON(){ > > // get the JSON Data > > $.getJSON("/bin/variables.js.pl <http://variables.js.pl>", > > { Weather: "Summary_Short", Tk_objects: > "label_cpu_used,label_memory_used", config_parms: > "web_href_shopping", Time_Now: "" }, > > ajaxCallBack > > ); > > // Update the data every 5 seconds (CAN CAUSE ALOT OF JSON CALLS, > IN HERE FOR TESTING) > > setTimeout("fireJSON();", 5000); > > } > > </script> > > </head> > > <body> > > Time Now: <span id="time_now" class="time_now"></span><br /> > > CPU: <span id="cpu" class="cpu"></span><br /> > > Memory Used: <span id="mem" class="mem"></span><br /> > > </body> > > </html> > > > Which for me, Generates (which updates every 5 seconds successfully): > > Time Now: 11:51 PM > > CPU: CPU 6.0% > > Memory Used: MB 44.7/33.8 > > > Source code is listed here: http://pastebin.com/Mdz0LzWH > > > Any changes or suggestions welcome > > > -- > > Regards, > > Ryan > > > ------------------------------------------------------------------------------ > Achieve unprecedented app performance and reliability > What every C/C++ and Fortran developer should know. > Learn how Intel has extended the reach of its next-generation tools > to help boost performance applications - inlcuding clusters. > http://p.sf.net/sfu/intel-dev2devmay > ________________________________________________________ > To unsubscribe from this list, go to: > http://sourceforge.net/mail/?group_id=1365 > > > > > > -- > Douglas A. Parrish > do...@ge... <mailto:do...@ge...> > > > ------------------------------------------------------------------------------ > Achieve unprecedented app performance and reliability > What every C/C++ and Fortran developer should know. > Learn how Intel has extended the reach of its next-generation tools > to help boost performance applications - inlcuding clusters. > http://p.sf.net/sfu/intel-dev2devmay > > > ________________________________________________________ > To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365 > |