1 回答
TA贡献1836条经验 获得超4个赞
ajax 默认是不会带 cookie,您需要手动设置以下 withCredentials
xhr.withCrendentials = true;
为了保障该属性生效,服务器必须显式地返回Access-Control-Allow-Credentials这个头信息:
Access-Control-Allow-Credentials: true
跨域问题。您先用*试试。
res.header("Access-Control-Allow-Origin", "*");
我这边是基于express写的接口:
var app = express();
//设置跨域访问
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*"); //*表示允许的域名地址,本地则为'http://localhost'
res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
res.header("Access-Control-Allow-Headers", "Content-Type, Content-Length, Authorization, X-Powered-By, Accept,X-Requested-With");
res.header("X-Powered-By", ' 3.2.1')
res.header("Content-Type", "application/json;charset=utf-8");
next();
});
添加回答
举报
