Send Error Message And Re-direct In Express.js
Learning Express.js. I have the following simple HTML form:
Solution 1:
To redirect in express:
res.redirect('/');
This doesn't exactly similate window.location
, but it does redirect.
However, I don't see why you should redirect, because you are sending the client a message, and before they get to see it you already redirected them.
A better way to approach your problem would be to use AJAX (submitting a form without reloading the page); check out this jQuery example (client-side obviously):
functionsubmitFormWithoutReloading() {
$.ajax({
type: "POST",
url: "/",
data: {
num1: $('#idOfYourFirstInput').val(),
num2: $('#idOfYourSecondInput').val()
},
success: function(res) {
alert(res); // This is what the server returns
}
});
}
Also, you can just use the provided variable __dirname
for the absolute path.
Post a Comment for "Send Error Message And Re-direct In Express.js"