首页 > Web开发 > 详细

ajax 跨域携带COOKIE

时间:2017-01-16 19:16:07      阅读:253      评论:0      收藏:0      [点我收藏+]

这个问题属于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");

ajax 跨域携带COOKIE

原文:http://www.cnblogs.com/10-8-2016-song/p/6290492.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!