Access to XMLHttpRequest at ‘http://localhost:3000/axios‘ from origin ‘null‘ has been blocked by COR
·
解决跨域时候发生的问题

在服务器js文件中修改跨域访问
原先
// 设置允许跨域访问该服务
app.all('*', function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.header('Access-Control-Allow-Headers', 'Content-Type');
res.header('Access-Control-Allow-Headers', 'mytoken');
next();
});
解决
// 设置允许跨域访问该服务
app.all(’’, function (req, res, next) {
res.header(“Access-Control-Allow-Origin”, "");
res.header(‘Access-Control-Allow-Methods’, ‘PUT, GET, POST, DELETE, OPTIONS’);
res.header(“Access-Control-Allow-Headers”, “X-Requested-With”);
res.header(‘Access-Control-Allow-Headers’, [‘Content-Type’, ‘mytoken’]);
next();
});
更多推荐
所有评论(0)