$.ajax({ url : 'http://remote.domain.com/corsrequest', data : data, dataType: 'json', type : 'POST', xhrFields: { withCredentials: true }, crossDomain: true, contentType: "application/json", ...
经过设置 withCredentials: true
,发送Ajax时,Request header中便会带上 Cookie 信息。javascript
对应客户端的 xhrFields.withCredentials: true
参数,服务器端经过在响应 header 中设置 Access-Control-Allow-Credentials = true
来运行客户端携带证书式访问。经过对 Credentials 参数的设置,就能够保持跨域 Ajax 时的 Cookie。这里须要注意的是:html
服务器端 Access-Control-Allow-Credentials = true
时,参数Access-Control-Allow-Origin
的值不能为 '*'
。java
关于axiso的跨域携带cookie见https://www.cnblogs.com/yihuite-zch/p/10670364.htmlajax