是否有Microsoft等效的HTML5 Server-Sent Events? [英] Is there a Microsoft equivalent for HTML5 Server-Sent Events?

查看:83
本文介绍了是否有Microsoft等效的HTML5 Server-Sent Events?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用HTML5 Server-Sent Events,如下所示:

I am using HTML5 Server-Sent Events as follows:

    SSEUpdate = new EventSource("http://example.com/update.php");
    SSEUpdate.onmessage = function(e){
      console.log(e.data);
    }

它在IE11中不起作用。 (控制台出错:'EventSource'未定义)是否有相同的Microsoft等价物,或者我必须做一些完全不同的事情?

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?

推荐答案

总之,没有。

Microsoft在任何版本中都没有包含SSE或等效的SSE IE浏览器IMO,你有两个不错的选择:

Microsoft has not included SSE or an equivalent of SSE in any version of IE. IMO, you have two good options:


  1. 使用polyfill - 我的测试 IE10和IE11中的这个polyfill 都是成功的。因为它以 if(全局中的EventSource)返回; 开头,所以它只会在不支持 EventSource

  2. 使用 websockets 而不是 - 虽然它需要更多的服务器端设置( ws:// 协议),但它适用于IE10和11 ,并提供更多选项,如双向通信。

  1. Use a polyfill - My tests with this polyfill in IE10 and IE11 were all successful. Since it starts with if ("EventSource" in global) return;, it'll only run in browsers that do not support EventSource.
  2. Use websockets instead - Although it requires more server-side setup (The ws:// protocol), it works in IE10 and 11 and provides more options such as bi-directional communication.

这篇关于是否有Microsoft等效的HTML5 Server-Sent Events?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆