Server-Sent Event: Receive Server-Sent Event Notifications

Receive Server-Sent Event Notifications

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

//Example explained:

// - Create a new EventSource object, and specify the URL of the page sending
//the updates (in this example "demo_sse.php")
// - Each time an update is received, the onmessage event occurs 
// - When an onmessage event occurs, put the received data into the element
//with id="result"

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

Related concepts

Receive Server-Sent Event Notifications

Server-Sent Event: Receive Server-Sent Event Notifications — Structure map

Clickable & Draggable!

Server-Sent Event: Receive Server-Sent Event Notifications — Related pages: