Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. <div class="row state-overview" id="statusCount"> </div>
  2.  
  3. let fsource;
  4. function getStatus() {
  5. if (typeof(EventSource) !== "undefined") {
  6. try {
  7. fsource.removeEventListener("status", stream, false);
  8. } catch (ex) {
  9. }
  10. fsource = new EventSource("-PHP FILE-");
  11. fsource.addEventListener("status", stream, false);
  12. } else {
  13. console.log("Oh no");
  14. }
  15. }
  16. function stream(e) {
  17. let data = JSON.parse(e.data);
  18. let html = '';
  19. $.each(data, function (key, value) {
  20. html += '<div class="col-lg-2 panel ' + key + ' ">';
  21. html += '<p>' + key + '</p>';
  22. html += '<label>' + value + '</label>';
  23. html += '</div>';
  24. });
  25. $('#statusCount').html(html);
  26. }
  27. getStatus();
  28.  
  29. event: status
  30. data: {"Online": 2, "Stopped": 3, "Alarm": 0, "Offline": 0}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement