加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Ajax跨域请求COOKIE无法带上的解决办法

发布时间:2020-12-15 21:31:10 所属栏目:百科 来源:网络整理
导读:原生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 : "htt
原生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(){
  },139)">  error:function(){
  }
})
服务器端设置:
 
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Origin: http://www.xxx.com");

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读