Skip to content

Buzzingz

Unleashing the Power of Code

  • HTML
  • CSS
  • JavaScript
  • Toggle search form

HTML SSE API

Posted on March 4, 2023April 1, 2023 By shani No Comments on HTML SSE API

HTML SSE API is a technology used to receive automatic updates from a server via HTTP connection, which allow web pages to update without the need for manual refreshing. It is part of the HTML5 specification and is supported by most modern web browsers.

SSE is based on a simple event-streaming protocol where the server sends a stream of data to the client over a single HTTP connection. This stream of data can contain any type of content, such as text, JSON, or XML. The server can push data to the client whenever there is an update, and the client can receive this data in real-time.

To use the SSE API in HTML, you can create an EventSource object and attach an event listener to it. The EventSource object listens for server-sent events and dispatches them to the listener when received.

Here is an example of using the SSE API in HTML:

<!DOCTYPE html>
<html>
<head>
	<title>SSE Example</title>
	<script>
		// create a new EventSource object
		var source = new EventSource("/sse.php");

		// add an event listener to the source object
		source.addEventListener('message', function(e) {
			// display the received message in the browser console
			console.log(e.data);
		}, false);
	</script>
</head>
<body>
	<h1>SSE Example</h1>
	<p>Check the browser console for updates.</p>
</body>
</html>

In this example, the HTML page creates a new EventSource object and attaches an event listener to it. The server-side script located at “/sse.php” sends a stream of data to the client, which is received by the event listener and displayed in the browser console.

HTML

Post navigation

Previous Post: HTML Web Workers API
Next Post: Basic CSS Tutorial For Beginners

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

HTML Tutorial

  • HTML History
  • HTML Editors
  • What is an HTML Element?
  • HTML Attributes
  • HTML Headings
  • HTML Paragraphs
  • HTML Styles
  • HTML Text Formatting
  • HTML Quotation and Citation Elements
  • HTML Comments
  • HTML Colors
  • HTML Styles – CSS
  • HTML Links
  • HTML images
  • HTML Favicon
  • HTML Tables
    • HTML Table Colgroup
    • HTML Table Colspan and Rowspan
    • HTML Table Headers
    • HTML Table Padding and Spacing
    • HTML Table Sizes
    • HTML Table Styling
  • HTML List
  • HTML Ordered Lists
  • HTML Unordered List
  • HTML other lists
  • HTML Block and Inline Elements
  • HTML class Attribute
  • HTML id Attribute
  • HTML Iframes
  • HTML JavaScript
  • HTML File Paths
  • HTML – The Head Element
  • HTML Layout Elements and Techniques
  • HTML Responsive Web Design
  • HTML Computer Code Elements
  • HTML Semantic Elements
  • HTML Style Guide
  • HTML Entities
  • HTML Symbols
  • HTML Emojis
  • HTML Encoding (Character Sets)
  • HTML Uniform Resource Locators(URL)
  • HTML Versus XHTML
  • HTML Forms
  • HTML Form Attributes
  • HTML Form Elements
  • HTML Form Target Attribute
  • HTML Input Attributes
  • HTML Input form Attributes
  • HTML Input Types
  • HTML Canvas Graphics
  • HTML SVG Graphics
  • HTML Multimedia
  • HTML Video
  • HTML Audio
  • HTML Plug-ins
  • HTML YouTube Videos
  • HTML Geolocation API
  • HTML Drag and Drop API
  • HTML Web Storage API
  • HTML Web Workers API
  • HTML SSE API
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions

Copyright © 2023 Buzzingz.

Powered by PressBook WordPress theme