document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <html>
  2. <head>
  3. <title>Seriality test of RGB Json data in web page using Seriality</title>
  4.   <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
  5.   <script type="text/javascript" src="json2.js"></script>
  6.  
  7.   <script type="text/javascript">
  8.  
  9.  $(document).ready(function(){
  10.       var serial;
  11.       var log = \'-\';
  12.  
  13.     function loop()
  14.     {
  15.       var json;
  16.       var data;
  17.       if (serial.available()) {
  18.         json = serial.readJSON();
  19.     //console.log("json:" + json);
  20.         document.getElementById("status").innerHTML = json;
  21.     if (json != undefined && json != "") {
  22.             data = JSON.parse(json);
  23.             document.getElementById("current").value = data.entry[\'photoVal\'] ;
  24.         }
  25.         serial.write(log);
  26.       }
  27.     }
  28.  
  29.      serial = (document.getElementById("seriality")).Seriality();
  30.       serial.begin(serial.ports[0], 9600);
  31.       serial.write(\'!\');
  32.         $(\'#on\').bind(\'click\', function() {
  33.         if (log === \'-\') {
  34.             log = \'!\';
  35.         } else {
  36.             log = \'-\';
  37.         }
  38.     console.log("click: " + log);
  39.     });
  40.  
  41.         setInterval(loop, 1250);
  42.   });
  43.  
  44.  
  45.   </script>
  46.  
  47. </head>
  48. <body>
  49.  
  50.   <object type="application/Seriality" id="seriality" width="0" height="0"></object>
  51.  
  52.   <h3>Parse JSON RGB data</h3>
  53.   <p>RGB Data formatted in JSON with an on/off button</p>
  54.  
  55.   <form>
  56.     <button id="on" type="button" value="-">On/Off</button>
  57.    
  58.     <br />Photo Resistor Value: <input id="current" type="text" />
  59.     <div id="status"></div>
  60.   </form>
  61.  
  62. </body>
  63. </html>
');