ReactJS - fetch function: Why am I getting uncaught (in promise) SyntaxError: Unexpected end of JSON input?
ReactJS - fetch function: Why am I getting uncaught (in promise) SyntaxError: Unexpected end of JSON input?
GET 请求成功运行,我现在正在尝试使用以下内容将 POST 转换为 url:
var data = {
'Content-Type': 'application/json',
'number': 'TEST12345'
}
var post = {
"number": "TEST12345",
"parameters":
{
"START_NUMBER" : {
"value": 5,
"effectiveDate": "2016/01/01 10:10"
}
}
}
var myInit = {
method: 'POST',
mode: 'cors',
headers: data,
body: JSON.stringify(post)
};
fetch('http://localhost:8080/form/upload/post/save', myInit)
.then(result=>{console.log(result.json())})
但我得到了以下日志:
一切似乎都是正确的,但为什么会出错:Uncaught (in promise) SyntaxError: Unexpected end of JSON input
?
正文方法returns 承诺
fetch('http://localhost:8080/form/upload/post/save', myInit)
.then(result => result.text())
.then(data => console.log(data))
GET 请求成功运行,我现在正在尝试使用以下内容将 POST 转换为 url:
var data = {
'Content-Type': 'application/json',
'number': 'TEST12345'
}
var post = {
"number": "TEST12345",
"parameters":
{
"START_NUMBER" : {
"value": 5,
"effectiveDate": "2016/01/01 10:10"
}
}
}
var myInit = {
method: 'POST',
mode: 'cors',
headers: data,
body: JSON.stringify(post)
};
fetch('http://localhost:8080/form/upload/post/save', myInit)
.then(result=>{console.log(result.json())})
但我得到了以下日志:
一切似乎都是正确的,但为什么会出错:Uncaught (in promise) SyntaxError: Unexpected end of JSON input
?
正文方法returns 承诺
fetch('http://localhost:8080/form/upload/post/save', myInit)
.then(result => result.text())
.then(data => console.log(data))