Server sent event EventStream does not trigger “onmessage” but Chrome Debug shows data in “EventStream” tab

老子叫甜甜 提交于 2019-12-04 00:32:39

According to the screenshot, your event-stream contains events of type "foo", not "message". That is only the default type (absent an event field in the event-stream). From the spec:

  1. Initialize event's type attribute to message, […]

  2. If the event type buffer has a value other than the empty string, change the type of the newly created event to equal the value of the event type buffer.

Here, you should set your listener to listen for "foo" events:

eventSource.addEventListener("foo", function() {...})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!