Using JSON Data for Live Information
Hi,
i need help.
At the moment i have this on my site dashboard.php
- $(function() {
- $.ajax({
- type: 'POST',
- url: 'inc/elevators.php',
- dataType: 'json',
- success: function(data) {
- console.log(data);
- }
- });
- });
And my elevators.php has this result
- [
- {
- "equipmentnumber":10015810,
- "type":"ELEVATOR",
- "description":"zu Gleis 6/7",
- "geocoordX":6.7941232,
- "geocoordY":51.2202587,
- "state":"ACTIVE",
- "stateExplanation":"available",
- "stationnumber":1401
- },
- {
- "equipmentnumber":10015811,
- "type":"ELEVATOR",
- "description":"zu Gleis 4/5",
- "geocoordX":6.7938916,
- "geocoordY":51.2203696,
- "state":"ACTIVE",
- "stateExplanation":"available",
- "stationnumber":1401
- },
- {
- "equipmentnumber":10015812,
- "type":"ELEVATOR",
- "description":"zu Gleis 13/14 (S-Bahn)",
- "geocoordX":6.7948481,
- "geocoordY":51.2200044,
- "state":"ACTIVE",
- "stateExplanation":"available",
- "stationnumber":1401
- },
- {
- "equipmentnumber":10015813,
- "type":"ELEVATOR",
- "description":"zu Gleis 17/18",
- "geocoordX":6.7952645,
- "geocoordY":51.2197097,
- "state":"ACTIVE",
- "stateExplanation":"available",
- "stationnumber":1401
- },
- {
- "equipmentnumber":10015805,
- "type":"ELEVATOR",
- "description":"zu Gleis 19/20",
- "geocoordX":6.7954912,
- "geocoordY":51.2196009,
- "state":"INACTIVE",
- "stateExplanation":"under maintenance",
- "stationnumber":1401
- },
- {
- "equipmentnumber":10015806,
- "type":"ELEVATOR",
- "description":"zu Gleis 11/12 (S-Bahn)",
- "geocoordX":6.7946775,
- "geocoordY":51.2200853,
- "state":"ACTIVE",
- "stateExplanation":"available",
- "stationnumber":1401
- },
- {
- "equipmentnumber":10015807,
- "type":"ELEVATOR",
- "description":"zu Gleis 15/16",
- "geocoordX":6.7950265,
- "geocoordY":51.2198242,
- "state":"ACTIVE",
- "stateExplanation":"available",
- "stationnumber":1401
- },
- {
- "equipmentnumber":10015809,
- "type":"ELEVATOR",
- "description":"zu Gleis 9/10",
- "geocoordX":6.7943761,
- "geocoordY":51.2201368,
- "state":"ACTIVE",
- "stateExplanation":"available",
- "stationnumber":1401
- }
- ]
On my dashboard.php i have an unordered list with elevators.
- <span class="badge badge-lg badge-danger">TRACK 4</span> <-- state=INACTIVE
- <span class="badge badge-lg badge-primary">TRACK 10</span> <-- state=ACTIVE
- <span class="badge badge-lg badge-danger">TRACK 19</span> <-- state=INACTIVE
- <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