AJAX/Fetch 在跨域情况下发送cookie并保持 sessionid一致 发表于 2017-08-18 | 分类于 笔记 Ajaxajax在跨域发送请求的时候需要添加 xhrFields 12345678910111213$.ajax({ url:'example.com', method:'post', datatype:'json', xhrFields: { withCredentials: true }, crossDomain: true, data:param, success:function(data){ console.log(data); } }) Fetchfetch在跨域发送请求的时候需要添加 credentials: “include” 12345678910fetch('http://example.com',{ method:'post', mode:'cors', credentials: "include", body: param}).then((response)=>{ return response.json(); }).then((responseData)=>{ console.log(responseData);}); 参考:Ajax跨域请求,同时保证session一致Fetch API with Cookie