【问题标题】:CORS withCredentials - support limited?CORS withCredentials - 支持有限?
【发布时间】:2013-11-09 02:45:34
【问题描述】:

我注意到某些浏览器似乎不支持 CORS 请求中的 withCredentials,至少在某些情况下是这样。具体来说,在 IE 10 中,尝试设置 xhr.withCredentials = true 会导致:

SCRIPT5022: InvalidStateError

在 Safari 5(但不是 6)中我得到了

INVALID_STATE_ERR: DOM Exception 11: An attempt was made to use an object that is not, or is no longer, usable.

再次,以回应相同的声明。

这些是已知问题,还是我的 XHR 设置有误?有哪些浏览器支持withCredentials的列表吗?

【问题讨论】:

  • 您是否在open 之后但在send 之前设置withCredentials
  • 根据the withCredentials spec:“设置时:如果状态不是UNSENTOPENED,或者设置了send() 标志,则抛出InvalidStateError 异常。 " 这表明它必须在调用send() 之前下注。然而,一些浏览器可能错误地比这个规范规则更严格。你能发布你的实际代码吗?

标签: javascript xmlhttprequest cors


【解决方案1】:

August 16, 2011 XHR draft 指定了设置withCredentials 的规则:

设置时:如果状态不是 OPENED 或 send() 标志为真,则抛出 INVALID_STATE_ERR 异常。

但是,January 17, 2012 draft 更宽松:

设置时:如果状态不是 UNSENT 或 OPENED,或者设置了 send() 标志,则抛出 InvalidStateError 异常。

您可能在调用 .open 之前设置了 withCredentials,这在 2011 规范中是不允许的,但在 2012 规范中是允许的。要同时满足这两个要求,只需在致电 .open 后将您的财产分配转移。

【讨论】:

    猜你喜欢
    • 2016-07-31
    • 1970-01-01
    • 2013-10-19
    • 2016-09-15
    • 2014-11-09
    • 2013-12-30
    • 2015-06-16
    • 2014-09-14
    • 2018-10-19
    相关资源
    最近更新 更多