[英]I'm trying to fetch my json site to enable API, but but got an error “Unexpected token < in JSON at position 0”
尝试获取 Json 站点时出错。 错误是“Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0”
我之前修复了一个与通过 {'mode':'no-cors'} 禁用 CORS 相关的错误。 然后在上面添加了这个问题
async componentDidMount() {
const url =("http://localhost/v1/Items/GetHardWaretypes", {'mode': 'no-cors'} );
const response = await fetch(url);
const data = await response.json();
console.log(data)
this.setState({products: data.results, loading: false})
}
尝试将标头Content-Type
和Accept
添加为application/json
。
async componentDidMount() {
const url =("http://localhost/v1/Items/GetHardWaretypes", {'mode': 'no-cors'} );
const response = await fetch(url, {
'Content-Type': 'application/json',
'Accept': 'application/json'
});
const data = await response.json();
console.log(data);
this.setState({products: data.results, loading: false})
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.