HTML5 服务器发送事件:如何设置 withCredentials 选项? [英] HTML5 Server-Sent Events: How to set withCredentials option?

查看:54
本文介绍了HTML5 服务器发送事件:如何设置 withCredentials 选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 WHATWG - 服务器发送的事件 下面是使用EventSource接口的API:

[Constructor(DOMString url, optional EventSourceInit eventSourceInitDict)]接口事件源:事件目标{只读属性 DOMString url;只读属性布尔值 withCredentials;//....};

<块引用>

withCredentials 属性必须返回它的值最后初始化.创建对象时,必须对其进行初始化为假.

简单例子:

var stock = new EventSource("events.php");stock.onmessage = 函数(事件){//警报(事件.数据);};

现在,如何在此示例中包含或设置 withCredentials?

解决方案

我还没试过,但是按照你链接的规范,我相信它会是这样的:

var stock = new EventSource("events.php", { withCredentials: true });

如果您访问 http://www.w3.org/TR/WebIDL/#idl-exceptions 然后向上滚动以查看上面的示例,您可以看到使用字典设置初始化值的类似模式.

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?

解决方案

I'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.

这篇关于HTML5 服务器发送事件:如何设置 withCredentials 选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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