A
A
Anton Ulanov2016-03-17 20:48:15
JavaScript
Anton Ulanov, 2016-03-17 20:48:15

How to display message from rest api in view?

Good time of the day. For example, when a user is successfully created using the POST method on the page localhost/api/user , the message {"statusCode":201,"message":"User Saved Successfully"} is displayed.
How can I display this message on the page from where I make a post request to create the most user? The address from which I am sending a POST request to localhost/post. An abstract example, I just want to understand how to implement it. I will be glad to links to mana or examples. Thank you all in advance

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
pomeo, 2016-03-17
@pomeo

These are the basics of ajax, make an ajax request to localhost/api/user, get your message and display it on the same page from which you never left.
Or do you mean what you send from the node? It's no different, you pass your message in

res.render('index', {
  msg: message
})

And then it depends on the template engine

A
Anton Ulanov, 2016-03-17
@antonsr98

I send the request with a regular html form, when the submit button is pressed, it transfers me to api / user, is this also solved through ajax?

H
HENSMEL, 2016-03-17
@HENSMEL

an excerpt from Flanagan if you like it, then download PDF
20.4. Interacting with the HTTP protocol using a tag

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question