I am making a fetch api POST request to a url. When I print the data to my console, it says undefined. Here is my code:
function arCall(url = '', data = {}) {
fetch(url, {
method: 'POST',
mode: 'cors',
cache: 'no-cache',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Basic ' +btoa('<my Username>:<my Password>'),
},
body: JSON.stringify(data)
})
.then((res) => console.log(res))
.then(data => console.log(data))
}
arCall('<my URL>', { id: 111 });
In the inspect tab on chrome, this is what the output looks like:
This is the Response object:
Could the reason for the undefined data be that I am getting a 403 forbidden error?