This question is seems to be already answered but my scenario is different. I am getting Unexpected token o in JSON at position 1 everytime. Can anyone help me to fix this.Thanks
here is my code
JavaScript
x
36
36
1
function send()
2
{
3
4
let detail = new FormData();
5
detail.append("start",true);
6
detail.append("user",'david');
7
8
postRequest("https://myjson-url/game.php?"
9
,detail, getData);
10
11
}
12
13
function getData(res)
14
{
15
16
let data = JSON.parse(res);
17
console.log(data);
18
19
}
20
//async function
21
async function checkStatus(res) {
22
if (!res.ok) {
23
throw new Error(await res.text());
24
}
25
return res;
26
}
27
28
//my post request
29
30
function postRequest(url, info, func){
31
fetch(url, {method: "POST", body: info})
32
.then(checkStatus)
33
.then(func)
34
.catch(console.error);
35
}
36
Advertisement
Answer
add json() let data = res.json();