daily pastebin goal
45%
SHARE
TWEET

Untitled

a guest Mar 19th, 2019 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top