node.js - Express.js Won't Render in Post Action -
node.JS is a little new, so I can find things on the internet. I have already solved this. This was because I was using the Called by this function To know all I changed it to add it to the Z file and call it from server side: I successfully solved it myself! I found out that this happened because I call the route from the customer to and I changed the route $ .jax from the client side. But when I try it in my code below, it never renders the initial page / contact was made, and when I call / contact / sendmail, all the functions inside / contact / sendmail are working but render not with. There was no error in it, nothing was done.
var contact = requirement ('../contactor / contact'); Module.exports = Function (app) {app.get ('/ contact', function (rick, ridge) {res.render ('contact');}); App.post ('/ contact / sendEmail', function (Rick, Race, Next) {var form = req.body; Contact.validators.form (form, function (error) {if (err) {return res.render ( 'User / register'); // it never works! / * Returns res.render ('contact', {error: err,}); * /} else {Contact.sendEmail (request, res, next );}});}); };
$ ('contact'). Submit (function (event, done) {var form = $ (this); var data = form.serializeArray (); // server side validation / / Each contact form field is required event.preventDefault (); $ .jax ({Type: 'post', url: '/ contact / sendEmail', data: form.serialize ()} .Done (function) {if (data.stats == 'OK') {$ ('# Contact-success'). Modal ('show');} else {returned ('please fill in all fields.', False);}});});
form (role = "form" Method = "post")
$ .jax . When I change this calling code by putting this code into the form and
$ Remove Ajax , so it's done. Thanks
form (role = "form" method = "post")
/ contact / sendEmail < / Code> just
/ contact .
Comments
Post a Comment