gpt4 book ai didi

javascript - 在 fetch api 中启用 CORS

转载 作者:可可西里 更新时间:2023-11-01 02:08:46 25 4
gpt4 key购买 nike

<分区>

我收到以下无法继续的错误消息

Failed to load https://site/data.json: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. localhost/:1 Uncaught (in promise) TypeError: Failed to fetch

我试图在我的 React js 文件中启用 CORS,但我无法获得预期的结果。我已经安装了一个 chrome 扩展程序并且可以正常工作。但是要在生产站点中使用它,我需要在我的代码中启用它。我应该如何正确安排代码以启用CORS

fetch(URL, {
mode: 'cors',
headers: {
'Access-Control-Allow-Origin':'*'
}
})
.then(response => response.json())
.then(data => {

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