To get a promise, you can do it.
promise.then(function(data) {
}, function(error) {...}
OR
You can also use the .catch () block to get the promise.
.then(){...}
.catch(){..}
Never skip to this part because the server has already sent a response
.then(function(response) {
console.log(response);
console.log(response.json());
response.json().then(function(value) {
console.log('access promise');
console.log(value);
});
You can write your code as follows:
fetch(deafaultUrl + '/v1/users/', {
headers: {
'Content-Type': 'application/json'
},
method: "POST",
body: JSON.stringify(userInfoParams)
})
.then(function(response) {
}
.catch(err){
}
});
source
share