gpt4 book ai didi

javascript - CORS 策略已阻止从源 'http://localhost:3000' 获取的访问权限

转载 作者:行者123 更新时间:2023-12-03 13:39:06 24 4
gpt4 key购买 nike

添加到数据库显示错误。我应该怎么办?

Access to fetch at 'http:xxx' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.


我的功能:
addItem = (e) => {
e.preventDefault();
const ob = {
X: 53.0331258,
Y: 18.7155611,
}
fetch("http://xxx", {
method: "post",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(ob)
})
.then(res => res.json())
.then(res => {
console.log(res);
})
}

最佳答案

尝试使用“no-cors”模式。

fetch('http://localhost:8080/example', {
mode: 'no-cors',
method: "post",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(ob)
})

关于javascript - CORS 策略已阻止从源 'http://localhost:3000' 获取的访问权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61238680/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com