Advertisement
ionstorm66

Untitled

Sep 10th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.71 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <title>Arduino SD Card Web Page using Ajax with XML</title>
  5.         <script>
  6.         function GetArduinoInputs()
  7.         {
  8.             nocache = "&nocache=" + Math.random() * 1000000;
  9.             var request = new XMLHttpRequest();
  10.             request.onreadystatechange = function()
  11.             {
  12.                 if (this.readyState == 4) {
  13.                     if (this.status == 200) {
  14.                         if (this.responseXML != null) {
  15.                             // extract XML data from XML file (containing switch states and analog value)
  16.                             document.getElementById("input1").innerHTML =
  17.                                 this.responseXML.getElementsByTagName('button1')[0].childNodes[0].nodeValue;
  18.                             document.getElementById("input2").innerHTML =
  19.                                 this.responseXML.getElementsByTagName('button2')[0].childNodes[0].nodeValue;
  20.                             document.getElementById("input3").innerHTML =
  21.                                 this.responseXML.getElementsByTagName('analog1')[0].childNodes[0].nodeValue;
  22.                         }
  23.                     }
  24.                 }
  25.             }
  26.             request.open("GET", "ajax_inputs" + nocache, true);
  27.             request.send(null);
  28.             setTimeout('GetArduinoInputs()', 1000);
  29.         }
  30.     </script>
  31.     </head>
  32.     <body onload="GetArduinoInputs()">
  33.         <h1>Arduino Inputs from SD Card Web Page using Ajax with XML</h1>
  34.         <p>Button 1 (pin 7): <span id="input1">...</span></p>
  35.         <p>Button 2 (pin 8): <span id="input2">...</span></p>
  36.         <p>Analog (A2): <span id="input3">...</span></p>
  37.     </body>
  38. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement