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())})
但是我得到了以下日志:
所有似乎都是正确的,但为什么错误:Uncaught (in promise) SyntaxError: Unexpected end of JSON input
?
答案 0 :(得分:1)
body方法返回一个promise
fetch('http://localhost:8080/form/upload/post/save', myInit)
.then(result => result.text())
.then(data => console.log(data))