$.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 信息。
對應客戶端的 xhrFields.withCredentials: true 參數,服務器端通過在響應 header 中設置 Access-Control-Allow-Credentials = true 來運行客戶端攜帶證書式訪問。通過對 Credentials 參數的設置,就可以保持跨域 Ajax 時的 Cookie。這里需要注意的是:
服務器端 Access-Control-Allow-Credentials = true時,參數Access-Control-Allow-Origin 的值不能為 '*' 。
關於axiso的跨域攜帶cookie見https://www.cnblogs.com/yihuite-zch/p/10670364.html
