Answer the question
In order to leave comments, you need to log in
Why does POST request have status code 204?
You need to send data from the body object as a post request.
Why is the request displayed twice in Network and the first one with status 204?
Tell me what I'm doing wrong.
let body = {
user: {
phone: `${ phone }`,
firstName: `${ name }`,
email: `${ email }`,
}
};
let url = `https://....`;
postData(url, body)
.then(data => {console.log(JSON.stringify(data))})
.catch(error => console.error(error));
function postData(url, data) {
return fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8',
'Accept': 'application/json'
},
body: JSON.stringify(data),
})
.then(response => response.json());
}
Answer the question
In order to leave comments, you need to log in
Everything is good.
For cross-domain requests, the browser does preflight , and for it 204 is the norm.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question