express解决跨域post请求变成OPTIONS

在app.js中加入以下代码:
在这里插入图片描述

代码如下:
app.all(’’, function(req, res, next) {
res.header(“Access-Control-Allow-Origin”, "
");
res.header(“Access-Control-Allow-Headers”, “X-Requested-With,Content-Type”);
res.header(“Access-Control-Allow-Methods”,“PUT,POST,GET,DELETE,OPTIONS”);
next();
});

猜你喜欢

转载自blog.csdn.net/qq_36971710/article/details/86152783