简体   繁体   中英

Fetch Error :-S SyntaxError: Unexpected token < in JSON at position 0 REACT

 let url = "/"
    fetch(url, {
      headers: {
        "Accept": "application/json",
        "Content-Type": "application/json"
      }
    })
    .then(resp => resp.json())
    .then(data => {
    setToken(1);
   })
   .catch(function(err) {  
    console.log('Fetch Error :-S', err);  
    });

I have a proxy OK: http://localhost:3001/people"

I have this json-server configurated

{
  "people": [
    {
      "id": "1",
      "name": "gustavo",
      "pass": "gustavo",
      "days": {
        "23/02/2021": [
          {
            "arrive": "09:00",
            "lunchstart": "12:00",
            "lunchend": "13:00",
            "exit": "17:00"
          }
        ],
        "24/02/2021": [
          {
            "arrive": "09:00",
            "lunchstart": "11:30",
            "lunchend": "13:00",
            "exit": "17:00"
          }
        ]
      }
    }
  ]
}

if a use "/1" it work., how to use just "/"?

I also can use INSOMNIA OR POSTMAN, it works with /people

i just changed the proxy to:

 "proxy": "http://localhost:3001"

and the fetch to:

let url = "people?name=gustavo" or
let url = "people"

I took 2 days to resolve this, but thank you God haha.

Anyone with another solution?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM