小编UiJ*_*Jin的帖子

fetch api 无法加载,不支持 url 方案“文件”

我尝试在本地主机上使用fetch,但没有成功。

这是我的代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>

        fetch("hi.txt").then(function(response){
            response.text().then(function(text){
                alert(text)
            })
        })
    </script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

hi.txt 文件与脚本文件位于同一文件夹中。

控制台中显示以下错误:

index.html:12 Fetch API cannot load file:///C:/~~~~/hi.txt. URL scheme "file" is not supported.

(~~~) 是路径

javascript asynchronous es6-promise fetch-api

15
推荐指数
1
解决办法
4万
查看次数

标签 统计

asynchronous ×1

es6-promise ×1

fetch-api ×1

javascript ×1