Using JSON Data for Live Information

Using JSON Data for Live Information

Hi,

i need help. 

At the moment i have this on my site dashboard.php

  1. $(function() {
  2. $.ajax({
  3.     type: 'POST',
  4.     url: 'inc/elevators.php',
  5.     dataType: 'json',
  6.     success: function(data) {       
  7.         console.log(data);
  8. }
  9. });
  10. });


And my elevators.php has this result


  1. [
  2. {
  3. "equipmentnumber":10015810,
  4. "type":"ELEVATOR",
  5. "description":"zu Gleis 6/7",
  6. "geocoordX":6.7941232,
  7. "geocoordY":51.2202587,
  8. "state":"ACTIVE",
  9. "stateExplanation":"available",
  10. "stationnumber":1401
  11. },
  12. {
  13. "equipmentnumber":10015811,
  14. "type":"ELEVATOR",
  15. "description":"zu Gleis 4/5",
  16. "geocoordX":6.7938916,
  17. "geocoordY":51.2203696,
  18. "state":"ACTIVE",
  19. "stateExplanation":"available",
  20. "stationnumber":1401
  21. },
  22. {
  23. "equipmentnumber":10015812,
  24. "type":"ELEVATOR",
  25. "description":"zu Gleis 13/14 (S-Bahn)",
  26. "geocoordX":6.7948481,
  27. "geocoordY":51.2200044,
  28. "state":"ACTIVE",
  29. "stateExplanation":"available",
  30. "stationnumber":1401
  31. },
  32. {
  33. "equipmentnumber":10015813,
  34. "type":"ELEVATOR",
  35. "description":"zu Gleis 17/18",
  36. "geocoordX":6.7952645,
  37. "geocoordY":51.2197097,
  38. "state":"ACTIVE",
  39. "stateExplanation":"available",
  40. "stationnumber":1401
  41. },
  42. {
  43. "equipmentnumber":10015805,
  44. "type":"ELEVATOR",
  45. "description":"zu Gleis 19/20",
  46. "geocoordX":6.7954912,
  47. "geocoordY":51.2196009,
  48. "state":"INACTIVE",
  49. "stateExplanation":"under maintenance",
  50. "stationnumber":1401
  51. },
  52. {
  53. "equipmentnumber":10015806,
  54. "type":"ELEVATOR",
  55. "description":"zu Gleis 11/12 (S-Bahn)",
  56. "geocoordX":6.7946775,
  57. "geocoordY":51.2200853,
  58. "state":"ACTIVE",
  59. "stateExplanation":"available",
  60. "stationnumber":1401
  61. },
  62. {
  63. "equipmentnumber":10015807,
  64.                  "type":"ELEVATOR",
  65. "description":"zu Gleis 15/16",
  66. "geocoordX":6.7950265,
  67. "geocoordY":51.2198242,
  68. "state":"ACTIVE",
  69. "stateExplanation":"available",
  70. "stationnumber":1401
  71. },
  72. {
  73. "equipmentnumber":10015809,
  74. "type":"ELEVATOR",
  75. "description":"zu Gleis 9/10",
  76. "geocoordX":6.7943761,
  77. "geocoordY":51.2201368,
  78. "state":"ACTIVE",
  79. "stateExplanation":"available",
  80. "stationnumber":1401
  81. }
  82. ]

On my dashboard.php i have an unordered list with elevators.

  1. <span class="badge badge-lg badge-danger">TRACK 4</span> <-- state=INACTIVE
  2. <span class="badge badge-lg badge-primary">TRACK 10</span> <-- state=ACTIVE
  3. <span class="badge badge-lg badge-danger">TRACK 19</span> <-- state=INACTIVE
  4. <span class="badge badge-lg badge-primary">TRACK 16</span> <-- state=ACTIVE
The order is random every day

Now i want to change the badge from danger to primary when the elevator has the state = ACTIVE and from primary to danger when the elevator has the state = INACTIVE

The Ajax Function should check this every 30 seconds.

I don't know how to do this all.

Thanks

Dennis