Login
Your Email
Pasword
Home
Write
Trending
History
Liked
Dashboard

What is SSE in HTML5?

Server-Sent Events allow a web page to get updates from a server.

Do you have similar website/ Product?
Show in this page just for only $2 (for a month)
Create an Ad
0/60
0/180
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.
Receive Server-Sent Event Notifications
var source = new EventSource("demo_sse.php");
source.onmessage = function(event)
{
 document.getElementById("result").innerHTML += event.data + "
";
};
Create a new EventSource object, and specify the URL of the page sending the updates .
 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..... }
 else {
 // No server-sent events support. 
}
CONTINUE READING
server-sent event
HTML5
Ayesha
Tech writer at newsandstory