Advertisement
Guest User

jQueryMobile AJAX

a guest
May 3rd, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
  5. <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
  6. <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
  7.  
  8. <meta charset="UTF-8">
  9. <script>
  10. $(document).on("pageshow", "#mainPage", function(){
  11. var refreshID = setInterval(function(){
  12. $.get("?requestState=0", function(data, status){
  13. alert("worked1");
  14. if(status=="success"){
  15. alert("worked2");
  16. if(data.indexOf("ventswitch=true") > -1){
  17. $("#switchvent").attr("checked", null);
  18. alert("inside");
  19. }
  20. else if(data.indexOf("ventswitch=false") > -1)
  21. $("#switchvent").attr("checked", "checked");
  22.  
  23. if(data.indexOf("lampswitch=true") > -1)
  24. $("#switchlamp").attr("checked", null);
  25. else if(data.indexOf("lampswitch=false") > -1)
  26. $("#switchlamp").attr("checked", "checked");
  27. alert("worked3");
  28. }
  29. });
  30. }, 5000);
  31.  
  32. //$.ajaxSetup({ cache: false });
  33.  
  34. $("#lampswitch").on("tap", function(){
  35. $.get("?requestState=1");
  36. });
  37.  
  38. $("#ventswitch").on("tap", function(){
  39. $.get("?requestState=3");
  40. });
  41. });
  42. </script>
  43. </head>
  44. <body>
  45. <div data-role="page" id="mainPage" data-theme="b">
  46. <div data-role="header" class="ui-content">
  47. <h1> Sistema de Automação Residencial </h1>
  48. </div>
  49. <div data-role="main" class="ui-content">
  50. <form id="form" style="text-align:center">
  51. <label for="switchvent">Lampada:</label>
  52. <span id="lampswitch"><input type="checkbox" id="switchvent" name="switch1"
  53.  
  54. data-role="flipswitch" data-on-text="On" data-off-text="Off" ></span>
  55. <!-- THE ONLY REASON TO USE <SPAN> ELEMENT IS BECAUSE <input
  56.  
  57. type="checkbox" data-role="flipswitch"> doesn't work with any click or touch events -->
  58. <label for="switchlamp">Ventilador:</label>
  59. <span id="ventswitch"><input type="checkbox" id="switchlamp" name="switch2"
  60.  
  61. data-role="flipswitch" data-on-text="On" data-off-text="Off" ></span>
  62. </form>
  63. </div>
  64. <div data-role="footer" class="ui-content">
  65. <h1> Versão 0.0.1 </h1>
  66. </div>
  67. </div>
  68. </body>
  69. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement