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的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");

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容