【发布时间】:2022-01-10 16:13:01
【问题描述】:
我的index.html 和data.json 文件都在同一个目录中
那么如何从 index.html 访问 json 文件呢?
在 index.html 中可能是这样的:
<script>
const data= require('./data.json') //obviously this won't work
</script>
根据this question 的所有答案,您必须先发送 index.html 文件,然后向服务器发出 fetch 请求以向您发送 json 文件
但是有没有办法将它们一起发送以避免延迟?
【问题讨论】:
标签: javascript html json