猿问

跨域后台设置了Access-Control-Allow-Origin:*,能访问到,但是浏览器会报错

1.会发两次请求,也能访问返回结果,但是浏览器报错;

2.浏览器报错


No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.

3.Content-Type:applycation/json;


疑问:问什么允许访问还会报错


天涯尽头无女友
浏览 54734回答 4
4回答

哈士奇WWW

看一下是不是返回头里Access-Control-Allow-Origin有多个

慕桂英4014372

exprss里是这么配置的,关键在于允许options请求以及options请求自动返回200看你说的返回两次可能是因为post请求没达到简单请求的要求,会发送options// cors跨域配置app.all('*', function (req, res, next) {    res.header('Access-Control-Allow-Origin', '*');    res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With, Current-Page');    res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');    if (req.method == 'OPTIONS') {        res.sendStatus(200);    } else {        next();    }});
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答