admin管理员组文章数量:1204592
According to WHATWG - Server-Sent Events below is the API for using EventSource interface:
[Constructor(DOMString url, optional EventSourceInit eventSourceInitDict)]
interface EventSource : EventTarget {
readonly attribute DOMString url;
readonly attribute boolean withCredentials;
//....
};
The withCredentials attribute must return the value to which it was last initialized. When the object is created, it must be initialized to false.
Simple example:
var stocks = new EventSource("events.php");
stocks.onmessage = function (event) {
//alert(event.data);
};
Now, how to include or set withCredentials in this example?
According to WHATWG - Server-Sent Events below is the API for using EventSource interface:
[Constructor(DOMString url, optional EventSourceInit eventSourceInitDict)]
interface EventSource : EventTarget {
readonly attribute DOMString url;
readonly attribute boolean withCredentials;
//....
};
The withCredentials attribute must return the value to which it was last initialized. When the object is created, it must be initialized to false.
Simple example:
var stocks = new EventSource("events.php");
stocks.onmessage = function (event) {
//alert(event.data);
};
Now, how to include or set withCredentials in this example?
Share Improve this question edited Apr 29, 2013 at 4:38 Charles 51.4k13 gold badges106 silver badges144 bronze badges asked Apr 28, 2013 at 18:54 user1646111user1646111 1- 1 Would you mind updating your answer with the final code? – Andrew Breksa Commented Jun 1, 2015 at 21:51
1 Answer
Reset to default 22I've not tried it, but going by the spec you link to, I believe it would be like this:
var stocks = new EventSource("events.php", { withCredentials: true });
If you go to http://www.w3.org/TR/WebIDL/#idl-exceptions then scroll up to see the example immediately above that, you can see a similar pattern of using a dictionary to set initialization values.
本文标签: javascriptHTML5 ServerSent Events How to set withCredentials optionStack Overflow
版权声明:本文标题:javascript - HTML5 Server-Sent Events: How to set withCredentials option? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738667433a2105786.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论