允许session共享后,ajax请求产生了新的session_id

当前情况是:
直接访问 cd.xxx.com 产生的session_id 与 访问 www.xxx.com 产生的session_id是一致的
但是在cd.xxx.com中使用ajax请求www.xxx.com会产生新的session_id导致验证失败!
有没有办法处理?,先谢过了!

阅读 4.5k
1 个回答

这个问题属于Ajax跨域携带Cookie的问题,找了一篇博文的解决方案。

原生ajax请求方式:

var xhr = new XMLHttpRequest();  
xhr.open("POST", "http://xxxx.com/demo/b/index.php", true);  
xhr.withCredentials = true; //支持跨域发送cookies
xhr.send();

jquery的post方法请求:

 $.ajax({
    type: "POST",
    url: "http://xxx.com/api/test",
    dataType: 'jsonp',
    xhrFields: {withCredentials: true},
    crossDomain: true,
})

服务器端设置:

header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Origin: http://www.xxx.com");

感谢原作者:
http://blog.sina.com.cn/s/blo...

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题