美文网首页
解决ajax跨域 session、cookie丢失问题

解决ajax跨域 session、cookie丢失问题

作者: 一生悬命Cat | 来源:发表于2019-02-27 23:09 被阅读0次

客户端 ajax加上以下语句

$.ajax({
url:url,
//加上这句话
xhrFields: {
           withCredentials: true
       },
       crossDomain: true,

success:function(result){
alert("test");
},
error:function(){
}
});

服务端 加上 header

        header('Access-Control-Allow-Origin:接收数据的客户端域名');
// 响应类型
        header('Access-Control-Allow-Methods:POST,GET');
// 响应头设置
        header('Access-Control-Allow-Headers:x-requested-with,content-type');
        header('Access-Control-Allow-Credentials:true');

相关文章

网友评论

      本文标题:解决ajax跨域 session、cookie丢失问题

      本文链接:https://www.haomeiwen.com/subject/fbtcuqtx.html