您的位置:首页 > 其它

ajax 跨域丢失cookie的问题

2015-10-08 16:51 507 查看
  
原生ajax请求方式:
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://xxxx.com/demo/b/index.php", true);
xhr.withCredentials = true; //支持跨域发送cookies
xhr.send();
jquery的ajax的post方法请求:
 $.ajax({
               type: "POST",url: "http://xxx.com/api/test",dataType: 'jsonp',xhrFields: {withCredentials: true},crossDomain: true,
           success:function(){
     },
           error:function(){
    }
})
服务器端设置:
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Origin: http://www.xxx.com");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: