Reputation: 31
I have a form on a webpage that asks for the client's username, password, age, and gender. I submit it to the nodejs server (express framework) when the user clicks the submit button. I want to query it against a database to check if the username and password already exists and if it does, can I send a message back to the browser saying the password or username already exists and somehow catch that message with javascript and use it to modify the page (to display the message that the username or password already exists) without using a template engine like jade or ejs?
Upvotes: 2
Views: 1422
Reputation: 4476
You can implement Rest post method to post your data like. Server code:
router.post('/create-user', function (req, res) {
var user = req.body;
usersService.createUser(user).then(function (status) {
res.json(status);
});
});
and in your client js code you need to have success method to check status. You can use jQuery post method
$.post( "api/create-user", formData , function( result) {
$( ".result" ).html( result );
});
Upvotes: 1