Reputation: 7575
GET request works successfully, and I am now trying to make a POST to a url with the following:
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())})
but I got the following log:
All seems correct but why the error: Uncaught (in promise) SyntaxError: Unexpected end of JSON input
?
Upvotes: 1
Views: 7065
Reputation: 3144
body methods returns a promise
fetch('http://localhost:8080/form/upload/post/save', myInit)
.then(result => result.text())
.then(data => console.log(data))
https://developer.mozilla.org/en-US/docs/Web/API/Body/text
Upvotes: 1