J
J
Junior Development2021-06-11 17:32:41
JavaScript
Junior Development, 2021-06-11 17:32:41

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?
60c373c1f04fe300143209.jpeg

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

1 answer(s)
S
Stalker_RED, 2021-06-11
@Stalker_RED

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 question

Ask a Question

731 491 924 answers to any question