Fetch Error :-S SyntaxError: Unexpected token < in JSON at position 0 REACT
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);
});
我有代理OK:http://localhost:3001/people
我配置了这个 json-server
{
"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"
}
]
}
}
]
}
如果使用“/1”就可以了。如何只使用“/”?
我也可以使用 INSOMNIA OR POSTMAN,它适用于 /people
我刚刚将代理更改为:
"proxy": "http://localhost:3001"
并提取到:
let url = "people?name=gustavo" or
let url = "people"
我花了2天的时间才解决这个问题,谢谢大神哈哈
有人有其他解决方案吗?
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);
});
我有代理OK:http://localhost:3001/people
我配置了这个 json-server
{
"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"
}
]
}
}
]
}
如果使用“/1”就可以了。如何只使用“/”?
我也可以使用 INSOMNIA OR POSTMAN,它适用于 /people
我刚刚将代理更改为:
"proxy": "http://localhost:3001"
并提取到:
let url = "people?name=gustavo" or
let url = "people"
我花了2天的时间才解决这个问题,谢谢大神哈哈
有人有其他解决方案吗?