ajax跨域获取cookie,Ajax无法获取cookie

项目中用axios获取数据的时候获取不到cookie,按照网上的方法设置了无数次都不行,之后想用ajax做一个测试,前端代码如下

var x = new XMLHttpRequest()

x.withCredentials =true

x.open('GET', 'http://a.com');

x.setRequestHeader("lang", "zh");

x.οnlοad=function(){

console.log(x.responseText);

};

x.send();

还是无法获取cookie,响应头如下

Access-Control-Allow-Credentials: true

Access-Control-Allow-Headers: x-requested-with, Content-Type,Cookie, Accept, multipart/form-data, application/x-www-form-urlencoded, lang, token, os, version, time

Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE

Access-Control-Allow-Origin: http://192.168.0.128:8020

Cache-Control: no-cache, must-revalidate, no-cache, private

Connection: close

Content-Type: application/json

Date: Thu, 06 Sep 2018 10:27:57 GMT

Pragma: no-cache

Proxy-Connection: keep-alive

Server: nginx/1.13.12

Transfer-Encoding: chunked

X-Content-Type-Options: nosniff

X-Powered-By: PHP/7.2.5

请求头如下

lang: zh

Origin: http://192.168.0.128:8020

Referer: http://192.168.0.128:8020/test/new_file.html?__hbt=1536228082860

User-Agent: Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Mobile Safari/537.36

从响应头来看后台设置的Access-Control-Allow-Credentials: true是没问题的,搞不懂问题出在哪里,求大佬指点!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值