Server-Sent events indicate that the webpage automatically obtains updates from the Server. This was also possible in the past, provided that the webpage had to ask if there were any available updates. When an event is sent through the server, the update will automatically arrive. Example: Facebook/Twitter updates, valuation updates, new blog posts, and competition results. The browser supports all mainstream browsers to send events on the server, except Internet Explorer. The EventSource object that receives Server-Sent Event Notifications is used to receive event notifications from the Server: [html] var source = new EventSource ("demo_sse.php"); source. onmessage = function (event) {document. getElementById ("result "). innerHTML + = event. data + "<br>" ;}; instance resolution: Create a New EventSource object and specify the URL of the page to be updated ("demo_sse.php" in this example ") each time an update is received, an onmessage event occurs. When an onmessage event occurs, push the received data into the element with the id as "result" to check that the Server-Sent event supports the following instances, we wrote an additional code to check the browser support for sending events on the server: [ht Ml] if (typeof (EventSource )! = "Undefined") {// Yes! Server-sent events support! // Some code...} else {// Sorry! No server-sent events support...} to make the above example run, you also need servers (such as PHP and ASP) that can send data updates ). The syntax of the server-side event stream is very simple. Set the "Content-Type" header to "text/event-stream ". Now you can start sending event streams. [Html] <? Php header ('content-Type: text/event-stream'); header ('cache-Control: no-cache'); $ time = date ('R '); echo "data: The server time is: {$ time} nn"; flush ();?> ASP code (VB) (demo_sse.asp): [html] <% Response. contentType = "text/event-stream" Response. expires =-1 Response. write ("data:" & now () Response. flush () %> code explanation: Set the header "Content-Type" to "text/event-stream", which specifies that the page will not be cached and output on the sending date (always with "data: in the above example, we use the onmessage event to get the message. However, you can also use other events: Event Description onopen when the connection to the server is opened onmessage when the message onerror is received when an error occurs