V
V
Vann Damm2020-05-28 16:06:25
JavaScript
Vann Damm, 2020-05-28 16:06:25

Does the response from the server, Response, work without data?

Request:

const response = await fetch(url, {method, mode : "cors", headers})
      console.log(response)

ROUTER:
router.get(
  "/getter",
  async (req, res) => {
    try {
      res.status(200).json({ message: "Ответ получен" });
    } catch (e) {
   // остальной код

I get this response: - But how do I get the object passed to json() with the message property
5ecfb7427e528531812306.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
yaroslav1996, 2020-05-28
@yaroslav1996

Try this for a start, fetch returns the stream, and you need to parse it:

fetch(url, {method, mode : "cors", headers}).then(function (response) {
    return response.json()
  })
  .then(function (data) {
    console.log('data', data)
  })

const response = await fetch(url, {method, mode : "cors", headers})
const result = await response.json();
console.log(result)

About Fetch API - https://developer.mozilla.org/en/docs/Web/API/Fetch_API

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question