| sidebar_position | 2 |
|---|
Create a new SSE instance:
var sse = $.SSE(url, settings);- url (string): URL for the server that will send the events to this page
- settings (object): The events and options for the SSE instance
var sse = $.SSE('http://example.com/sse-server.php', {
onMessage: function(e){
console.log("Message received:", e.data);
}
});Start the EventSource communication.
sse.start();Returns: true if started successfully, false if already running
Behavior:
- Automatically detects if native EventSource is available
- Falls back to Ajax polling if:
- EventSource is not supported by the browser
forceAjaxoption is set totrue- Custom headers are provided (EventSource doesn't support custom headers)
Stop the EventSource communication.
sse.stop();Returns: true if stopped successfully, false if not running
Behavior:
- Closes the connection
- Triggers the
onEndcallback - Cleans up the instance