- 在ajax请求中加上这个字段
xhrFields:{
withCredentials:true
}
因为在默认情况下,跨源请求不提供凭据(cookie、HTTP认证及客户端SSL证明等)。通过将withCredentials属性设置为true,可以指定某个请求应该发送凭据。如果服务器接收带凭据的请求,会用下面的HTTP头部来响应
- 完整代码
$.ajax({
type:"GET",
url:"https://xxxx/api/xxxxxx",
dataType:'json',
xhrFields:{
withCredentials:true
},
crossDomain:true,
success:function(res){
console.log(res)
}
})
更多推荐
ajax请求中传递cookie数据
发布评论