Get the App
SLTechnology News&Howtos  ›  Development  › 

Case Analysis of events sent by HTML5 Server

Shulou Source: shulou.com Published: 2022-06-01 05:15:55 09月23日 Update

This article introduces the relevant knowledge of "HTML5 server sending event instance analysis". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The HTML5 server sends an event (server-sentevent) that allows a web page to get updates from the server.

Server-Sent event-one-way messaging

The Server-Sent event means that a web page automatically gets updates from the server.

It was possible to do this in the past, as long as the page had to ask if any updates were available. Updates can arrive automatically by sending events through the server.

Examples: Facebook/Twitter updates, stock price updates, new blog posts, race results, etc.

Browser support

InternetExplorerFirefoxOperaGoogleChromeSafari

All major browsers support sending events from the server, except for InternetExplorer.

Receive Server-Sent event notifications

The EventSource object is used to receive event notifications sent by the server:

Example

Var source=new EventSource ("demo_sse.php")

Source.onmessage=function (event)

{

Document.getElementById ("result") [xss_clean] + = event.data + "

"

}

Instance resolution:

Create a new EventSource object, and then specify the URL of the page that sends the update (in this case, "demo_sse.php")

Every time an update is received, an onmessage event occurs

When the onmessage event occurs, push the received data into the element whose id is "result"

This is the end of the content of "HTML5 Server sending event instance Analysis". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Events servers services updates instances web pages case analysis analysis content objects more browsers knowledge support browsing practicality learning and then mainstream examples Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Tech Info Docker Linux vpn