简体   繁体   English

I'm trying to fetch my json site to enable API, but but got an error “Unexpected token < in JSON at position 0”

[英]I'm trying to fetch my json site to enable API, but but got an error “Unexpected token < in JSON at position 0”

Error while I'm trying to fetch my Json site.尝试获取 Json 站点时出错。 The error is "Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0"错误是“Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0”

I fixed an error before related with disable CORS through {'mode': 'no-cors'}.我之前修复了一个与通过 {'mode':'no-cors'} 禁用 CORS 相关的错误。 And after that hppended this problem above然后在上面添加了这个问题

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})
}

Try adding the headers Content-Type and Accept as application/json .尝试将标头Content-TypeAccept添加为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.

相关问题 JSON中位置0处的意外令牌u我正在尝试做一个插件 - Unexpected token u in JSON at position 0 i'm trying to do a plugin 在位置0错误的JSON中出现意外的标记m - Unexpected token m in JSON at position 0 error Javascript Fetch : Error Unexpected token &lt; in JSON at position 0 - Javascript Fetch : Error Unexpected token < in JSON at position 0 当我尝试在我的 React 项目中获取数据时,我收到此错误: Uncaught (in promise) SyntaxError: Unexpected token &lt; in JSON at position 0 - When i try to fetch data in my React project, then I get this error: Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0 获取 API SyntaxError: Unexpected token { in JSON at position 169681 - Fetch API SyntaxError: Unexpected token { in JSON at position 169681 获取错误:-S SyntaxError: Unexpected token &lt; in JSON at position 0 REACT - Fetch Error :-S SyntaxError: Unexpected token < in JSON at position 0 REACT 错误:位置 0 处的 JSON 中出现意外标记 &lt; - Error: Unexpected token < in JSON at position 0 JSON中位于位置0的意外令牌I - Unexpected token I in JSON at position 0 语法错误:JSON 中位置 0 处的意外标记 p 在提取中 - SyntaxError: Unexpected token p in JSON at position 0 In fetch 提取-SyntaxError:JSON中位置0处的意外令牌&lt; - Fetch - SyntaxError: Unexpected token < in JSON at position 0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM