GET 请求成功运行,我现在尝试使用以下内容对网址进行 POST:
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())})
但我得到以下日志:
一切似乎都是正确的,但为什么会出现错误:未捕获( promise 中)语法错误:JSON 输入意外结束
?
最佳答案
主体方法返回一个 promise
fetch('http://localhost:8080/form/upload/post/save', myInit)
.then(result => result.text())
.then(data => console.log(data))
关于javascript - ReactJS - 获取函数: Why am I getting uncaught (in promise) SyntaxError: Unexpected end of JSON input?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38880155/