zhaoqige / 6w-grid-lite

Web User Interface for GWS Beijing Firmware since March 2017
MIT License
0 stars 0 forks source link

Use "Event Stream" to read updates from server? #45

Closed zhaoqige closed 7 years ago

zhaoqige commented 7 years ago

Client Side:

var source = new EventSource("demo_sse.php");
source.onmessage = function(event) {
    document.getElementById("result").innerHTML += event.data + "<br>";
};

Server Side:

<?php
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');

$time = date('r');
echo "data: The server time is: {$time}\n\n";
flush();
?>

Thank Steven for his input.

zhaoqige commented 7 years ago

Rejected with reason: event IE9+ don't support this.