What is SSE in HTML5?
Server-Sent Events allow a web page to get updates from a server.
A server-sent event is when a web page automatically gets updates from a server. This was also possible before, but the web page would have to ask if any updates were available. With server-sent events, the updates come automatically.
Create a new EventSource object, and specify the URL of the page sending the updates .
Receive Server-Sent Event Notifications
|var source = new EventSource("demo_sse.php");
source.onmessage = function(event)
document.getElementById("result").innerHTML += event.data + "
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"
To check Server-Sent Events Support
|if(typeof(EventSource) !== "undefined") |
// Server-sent events supported // Some code..... }
// No server-sent events support.
Tech writer at newsandstory
Total 612 views