JS Coding Questions Logo
JS Coding Questions
#59💼 Interview💻 Code

How do you receive server-sent event notifications

Advertisement

728x90

The EventSource object is used to receive server-sent event notifications. For example, you can receive messages from server as below,

javascript
1if (typeof EventSource !== "undefined") {
2
3var source = new EventSource("sse_generator.js");
4
5source.onmessage = function (event) {
6  document.getElementById("output").innerHTML += event.data + "<br>";
7};
8}

Advertisement

Responsive Ad
🎯 Practice NowRelated Challenge

JavaScript Coding Exercise 60

Test your knowledge with this interactive coding challenge.

Start Coding

Advertisement

728x90
59of476