ajax设置跨域报错
后端
前端
报错
express 也就是你的后端代码设置跨域:
app.js中加入这段代码:
// 允许跨域
app.all('*', function(req, res, next) {
console.log(req.headers.origin)
console.log(req.environ)
res.header("Access-Control-Allow-Origin", '*');
// res.header("Access-Control-Allow-Origin", req.headers.origin);
res.header("Access-Control-Allow-Headers", "Content-Type,Content-Length, Authorization, Accept,X-Requested-With");
res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
res.header("Access-Control-Allow-Credentials","true");
res.header("X-Powered-By",' 3.2.1')
if(req.method === "OPTIONS") res.send(200);/*让options请求快速返回*/
else next();
});
如有帮助,麻烦点个【采纳此答案】 谢谢啦^.^