D
D
Denoro552018-10-05 02:07:43
Node.js
Denoro55, 2018-10-05 02:07:43

How to get response from server without reload on node.js?

How to get response from server without reload on node.js

router.post('/send', function(req, res, next) {
     res.json({status: 'Ваше письмо было отправлено!'});
});

I'm using express
Let's say I submitted a form and got a json response. How can it be read and used on the client side? Let's say that without a reboot, a window with an answer appears.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anubis, 2018-10-05
@Anubis

async function someAsyncRequest() {
  const result = await fetch('https://jsonplaceholder.typicode.com/todos/1');
  const json = await result.json();
  console.log(json);
}

Try it out: https://jsfiddle.net/ajrbcxpm/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question