Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div class="row state-overview" id="statusCount"> </div>
- let fsource;
- function getStatus() {
- if (typeof(EventSource) !== "undefined") {
- try {
- fsource.removeEventListener("status", stream, false);
- } catch (ex) {
- }
- fsource = new EventSource("-PHP FILE-");
- fsource.addEventListener("status", stream, false);
- } else {
- console.log("Oh no");
- }
- }
- function stream(e) {
- let data = JSON.parse(e.data);
- let html = '';
- $.each(data, function (key, value) {
- html += '<div class="col-lg-2 panel ' + key + ' ">';
- html += '<p>' + key + '</p>';
- html += '<label>' + value + '</label>';
- html += '</div>';
- });
- $('#statusCount').html(html);
- }
- getStatus();
- event: status
- data: {"Online": 2, "Stopped": 3, "Alarm": 0, "Offline": 0}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement