garage_door_opener.html 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <link rel="stylesheet" type="text/css" href="garage_door_opener.css">
  5. <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
  6. <meta charset="UTF-8">
  7. <title>Garage Remote</title>
  8. </head>
  9. <script>
  10. var xmlHttp = null;
  11. function pushTheButton(door)
  12. {
  13. var url = "/garage_door_opener.lua?door=" + door;
  14. xmlHttp = new XMLHttpRequest();
  15. xmlHttp.onreadystatechange = processRequest;
  16. xmlHttp.open("GET", url, true);
  17. xmlHttp.send( null );
  18. }
  19. function processRequest()
  20. {
  21. if(xmlHttp.readyState == 0)
  22. {
  23. document.getElementById('label').innerHTML = 'Initalizing...';
  24. }
  25. else if(xmlHttp.readyState == 1)
  26. {
  27. document.getElementById('label').innerHTML = 'Server connection established.';
  28. }
  29. else if(xmlHttp.readyState == 2)
  30. {
  31. document.getElementById('label').innerHTML = 'Request received.';
  32. }
  33. else if(xmlHttp.readyState == 3)
  34. {
  35. document.getElementById('label').innerHTML = 'Processing request.';
  36. }
  37. else if(xmlHttp.readyState == 4)
  38. {
  39. if(xmlHttp.status == 200)
  40. {
  41. document.getElementById('label').innerHTML = xmlHttp.responseText;
  42. }
  43. else if(xmlHttp.status == 400)
  44. {
  45. document.getElementById('label').innerHTML = 'Bad request.';
  46. }
  47. }
  48. }
  49. </script>
  50. <body bgcolor="#777777">
  51. <link href='http://fonts.googleapis.com/css?family=Khand:700' rel='stylesheet' type='text/css'>
  52. <a href="#" onclick="pushTheButton(1); " class="button"">
  53. <span>Door 1</span>
  54. </a>
  55. <a href="#" onclick="pushTheButton(2); " class="button"">
  56. <span>Door 2</span>
  57. </a>
  58. <div id="label">Text goes here</div>
  59. </body>
  60. </html>