问题描述
我已经在谷歌上搜索了几个小时,我以为我只是在这里问。出于某种原因,我的“require()”不起作用。 recuirejs 已包含在内,据我所知,我的返回值应该是我的数据,其顺序与我的 json 文件完全相同。
这是我的代码:
$(document).ready(async function() {
let data = await fetchData('./data/file.json');
console.log(data);
}
// fetch and return data
function fetchData(path) {
return require([path]);
}
我最初有这个解决方案(它与本地主机一起工作,但我需要它没有主机):
function fetchData(path) {
return fetch(path).then(response => {
return response.json().then((data) => {
return data;
}).catch((err) => {
console.log(err);
})
});
}
它给了我几个脚本错误和 MIME 类型不匹配,而且它记录了这个而不是我的数据:
s(e,t,i)
arguments: null
caller: null
>defined: function defined(e)
isBrowser: true
length: 3
name: "s"
>prototype: Object { … }
>specified: function specified(e)
>toUrl: function toUrl(e)
>undef: undef(i)
我不知道我还应该尝试什么。
谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)