Html 是否有针对 HTML5 服务器发送事件的 Microsoft 等效项?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24498141/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a Microsoft equivalent for HTML5 Server-Sent Events?
提问by GiantDuck
I am using HTML5 Server-Sent Events as follows:
我使用 HTML5 服务器发送的事件如下:
SSEUpdate = new EventSource("http://example.com/update.php");
SSEUpdate.onmessage = function(e){
console.log(e.data);
}
It does not work in IE11. (Error in console: 'EventSource' is undefined
) Is there an identical Microsoft equivalent, or do I have to do something completely different?
它在 IE11 中不起作用。(控制台中的错误:)'EventSource' is undefined
是否有相同的 Microsoft 等效项,或者我必须做一些完全不同的事情?
回答by Mooseman
In a word, no.
一句话,没有。
Microsoft has not included SSE or an equivalent of SSE in any version of IE. IMO, you have two good options:
Microsoft 尚未在任何版本的 IE 中包含 SSE 或 SSE 的等效项。IMO,您有两个不错的选择:
- Use a polyfill- My tests with this polyfillin IE10 and IE11 were all successful. Since it starts with
if ("EventSource" in global) return;
, it'll only run in browsers that do not supportEventSource
. - Use websocketsinstead- Although it requires more server-side setup (The
ws://
protocol), it works in IE10 and 11and provides more options such as bi-directional communication.
- 使用 polyfill- 我在 IE10 和 IE11 中使用这个 polyfill 的测试都成功了。由于它以 开头
if ("EventSource" in global) return;
,因此它只会在不支持EventSource
. - 使用的WebSockets代替-尽管它需要更多的服务器端设置(该
ws://
协议),它工作在IE10和11,并提供更多的选项,如双向通信。