[英]**No 'Access-Control-Allow-Origin' header is present on the requested resource.**
[英]No 'Access-Control-Allow-Origin' header is present on the requested resource. NodejS Express
我收到此錯誤
(index):1 Access to XMLHttpRequest at 'https://example.com/crm/addlead' from origin 'https://abc.examplehosting.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
我也在我的 app.js 中添加了這段代碼
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
請提出可能是什么問題。
您需要安裝cors
CORS 。
const cors = require('cors')
var corsOptions = {
origin: '*',
optionsSuccessStatus: 200 // some legacy browsers like IE11
}
app.use(cors(corsOptions));
嘗試將cors
層添加到您的應用程序中,
npm install --save cors
// In your server file
var cors = require('cors');
...
app.use(cors());
在此處了解有關 cors的更多詳細信息
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.