withCredentials是XMLHttpRequest的 属性
默认值为false。在获取同域资源时设置 withCredentials 没有影响。
- true:在跨域请求时,会携带用户凭证
- false:在跨域请求时,不会携带用户凭证;返回的 response 里也会忽略 cookie
设置withCredentials,后端设置Access-Control-Allow-Origin: * 会报错
必须设置对应的请求域名
相关链接
https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest/withCredentials