【发布时间】:2020-11-17 17:40:18
【问题描述】:
我要获取这个urlhttps://github.com/ProjectSakura/OTA/blob/10/changelog/changelog_beryllium.txt#L2的数据
我正在尝试使用 fetch api 来获取数据,但我得到了 cors 错误
这就是我想要做的事情
async function showmodal1() {
console.log("hello")
const data = await
fetch('https://github.com/ProjectSakura/OTA/blob/10/changelog/changelog_beryllium.txt');
console.log(data)
}
showmodal1();
有没有办法获取github txt文件的数据 我试图通过互联网找到这个,但我找不到任何东西 提前感谢您的帮助
编辑:
Access to fetch at 'https://github.com/ProjectSakura/OTA/blob/10/changelog/changelog_beryllium.txt' from origin 'http://127.0.0.1:5500' has been blocked by CORS policy: 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. changelog.html:361
GET https://github.com/ProjectSakura/OTA/blob/10/changelog/changelog_beryllium.txt net::ERR_FAILED
showmodal1 @ changelog.html:361
(anonymous) @ changelog.html:365
dispatch @ jquery.min.js:3
r.handle @ jquery.min.js:3
changelog.html:364
Uncaught (in promise) TypeError: Failed to fetch
这是错误日志
编辑2:
Promises/Fetch in JavaScript: how to extract text from text file
Reading code from GitHub as text (raw) in a web page
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
这是我在写问题之前发现的链接
【问题讨论】:
-
我不知道这个问题有什么问题值得-1分:(
-
如果您想要我的支持,请显示研究。
-
已编辑先生,我比较新,所以我不知道如何提出好的问题,谢谢你指导我@AaronBell
标签: javascript promise async-await cors fetch