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);
}
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?
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:
- 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 supportEventSource
. - 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.
SSE native support for IE is not there. You can achieve same thing using polyfill
来源:https://stackoverflow.com/questions/24498141/is-there-a-microsoft-equivalent-for-html5-server-sent-events