0

I am using post method to submit form in node js. Now when I submit the form, I want to show the error message from node server if login fails. I am setting the message as res.send("") but it is showing message on another window. So please help me to solve this?

1
  • 1
    Show us some code, and what are you really looking to changes... Commented Jan 27, 2016 at 11:10

2 Answers 2

1

You could make an Ajax call from your form to your node server API, then depending on the result from your server, show a message.

Jquery example:

$.ajax({
       method: "POST",
       url: "/api"
       data: {login_data_here}
})
.success(function(msg) {
       // redirect to admin area etc
})
.error(function(msg) {
       // show login for with a failure message
});

Node API server would return something like this:

res.writeHead(200, { 'Content-Type': 'application/text' }); 
res.end('Login Success');

Or this on fail:

res.writeHead(400, { 'Content-Type': 'application/text' }); 
res.end('Login Fail');
Sign up to request clarification or add additional context in comments.

Comments

0

You can use this module for persisted flash messages between page redirects - https://www.npmjs.com/package/connect-flash

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.