XMLHttpRequest.withCredentials
特性为
布尔
that indicates whether or not cross-site
Access-Control
requests should be made using credentials such as cookies, authorization headers or TLS client certificates. Setting
withCredentials
has no effect on same-site requests.
In addition, this flag is also used to indicate when cookies are to be ignored in the response. The default is
false
.
XMLHttpRequest
from a different domain cannot set cookie values for their own domain unless
withCredentials
被设为
true
before making the request. The third-party cookies obtained by setting
withCredentials
to true will still honor same-origin policy and hence can not be accessed by the requesting script through
document.cookie
or from response headers.
注意: This never affects same-site requests.
注意:
XMLHttpRequest
responses from a different domain
cannot
set cookie values for their own domain unless
withCredentials
被设为
true
before making the request, regardless of
Access-Control-
header values.
var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://example.com/', true);
xhr.withCredentials = true;
xhr.send(null);
| 规范 | 状态 | 注释 |
|---|---|---|
| XMLHttpRequest | 实时标准 | WHATWG (Web 超文本应用程序技术工作组) 实时标准 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
withCredentials
|
Chrome 3 | Edge 12 |
Firefox
3.5
|
IE
10
|
Opera 12 | Safari 4 | WebView Android ≤37 | Chrome Android 18 |
Firefox Android
4
|
Opera Android 12 | Safari iOS 3.2 | Samsung Internet Android 1.0 |
完整支持
见实现注意事项。
XMLHttpRequest