Horje
How to Receive Server-Sent Event Notifications

The EventSource object is used to receive server-sent event notifications:


Example of Receiving Server-Sent Event Notifications

The EventSource object is used to receive server-sent event notifications:
index.html
Example: HTML
<h1>Getting server updates</h1>
<div id="result"></div>

<script>
if(typeof(EventSource) !== "undefined") {
  var source = new EventSource("demo_sse.php");
  source.onmessage = function(event) {
    document.getElementById("result").innerHTML += event.data + "<br>";
  };
} else {
  document.getElementById("result").innerHTML = "Sorry, your browser does not support server-sent events...";
}
</script>

Output should be:

Example of Receiving Server-Sent Event Notifications

Example explained: Receive Server-Sent Event Notifications






Category:
Web Tutorial
Sub Category:
HTML SSE API
Uploaded by:
Admin


Read Article
https://develop.horje.com/learn/1434/reference