console snapshotI am calling one fetch API which giving the response header 'key-name':'value'. I checked in the chrome developer tools network tab. It showing the value. However, I am trying to read it during API response it's showing empty. I tried multiple ways but still not working. Below is my code.
const requestOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
pid: d,
cy: v
}
)
};
fetch('https://mysite/api/manage/', requestOptions)
.then(res => res.json())
.then(jsong => {
console.log(jsong);
console.log(jsong.headers);
}).catch((err) => {
console.log(err);
});
Please help. I added a console snapshot and network response snapshot as well. network response snapshot
I got the solution and here is the answer. It might be useful for someone
fetch('mysite.com/api/manage-cart/', requestOptions)
.then(res => res.headers.get('cart_info')
)
.then(res => {
window.localStorage.setItem("cartData", JSON.stringify(res));
}).catch((err) => {
console.log(err);
}); .
I am storing the value on local storage for further use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With