How to fix EventSource
onmessage not working in JavaScript All in One
SSE:
Server-Sent Events
/ 服务端推送
error ❌
window.addEventListener(`load`, (e) => {
console.log(`page loaded ✅`);
if (!!window.EventSource) {
const img = document.querySelector(`#sse`);
const source = new EventSource('http://localhost:3000/sse');
source.onopen = (event) => {
console.log(`✅ Connection to server opened.`, event);
};
source.onmessage = (event) => {
const data = event.data;
console.log(`
标签:const,log,working,res,fix,JavaScript,console,data,event
From: https://www.cnblogs.com/xgqfrms/p/17783689.html