这篇文章主要介绍了Ajax跨域请求COOKIE无法带上怎么办,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
1、原生ajax请求方式:
1 var xhr = new XMLHttpRequest();
2 xhr.open("POST", "http://xxxx.com/demo/b/index.php", true);
3 xhr.withCredentials = true; //支持跨域发送cookies
4 xhr.send();
2、jquery的ajax的post方法请求:
$.ajax({
type: "POST",
url: "http://xxx.com/api/test",
dataType: 'json',
// 允许携带证书
xhrFields: {
withCredentials: true
},
// 允许跨域
crossDomain: true,
success:function(){
},
error:function(){
}
})
3、服务器端设置:
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Origin: http://www.xxx.com");
感谢你能够认真阅读完这篇文章,希望小编分享的“Ajax跨域请求COOKIE无法带上怎么办”这篇文章对大家有帮助,同时也希望大家多多支持天达云,关注天达云行业资讯频道,更多相关知识等着你来学习!