P
P
PRIYD2020-08-26 22:53:49
JavaScript
PRIYD, 2020-08-26 22:53:49

Why is there no response from the server?

Hello. I send a request to the server via fetch:

function sendRequest(url, data) {
    const response = fetch(url, {
        method: 'POST',
        headers: {
            'Content-Type' : 'application/json'
        },
        body: JSON.stringify(data)
    });

    return response; 
}


Everything is ok, the request was accepted, processed. I answer:
router.post('/sign-up', (req, res) => {
    controller.createUser(req.body)
        .then(data=> {
            res.send(data);
    });
});


And the client receives just an empty response, without a body. I tried to send via res.json(response), but the same problem.

Question: how to get a response from the server?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2020-08-26
@PRIYD

router.post('/sign-up', (req, res) => {
    controller.createUser(req.body)
        .then(data=> {
            // а тут точно что-то есть в ответ?
            console.log(data) // ?
            res.send(data);
    });
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question