报这个错误:Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0
报这个错误:Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0
fetch('./data.json',{
methods:'get'
}).then(function(response){
return response.json()
}).then(function(res){
console.log(res)
}).catch(function(err){
console.log(err)
})
出现 Unexpected token < in JSON at position 0
90% 是返回的数据不是合法的 json 格式,或者内容为空,在开发者工具 network 下仔细检查 fetch 返回值或者在 response.json()
前先 console.log(response)
好像你的
method
写错了,你多加了s,写成了methods
, 应该是method
吧
10 回答11.2k 阅读
6 回答3k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.7k 阅读✓ 已解决
3 回答1.9k 阅读✓ 已解决
3 回答2.3k 阅读✓ 已解决
先别直接调用.json() 打印看看response里面是什么内容啊?