hahn-admin/app/view/sse.html

35 lines
984 B
HTML
Raw Normal View History

2025-07-03 11:08:07 +08:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SSE Test</title>
</head>
<body>
<h1>SSE Test</h1>
<div id="output"></div>
<script>
if (typeof(EventSource) !== "undefined") {
var source = new EventSource("http://127.0.0.1:8787/index/header");
source.onopen = function(event) {
console.log("Connection to server opened.");
};
source.onmessage = function(event) {
var output = document.getElementById("output");
output.innerHTML += event.data + "<br>";
};
source.onerror = function(event) {
console.log("EventSource failed:", event);
source.close();
};
} else {
document.getElementById("output").innerHTML = "Sorry, your browser does not support server-sent events...";
}
</script>
</body>
</html>