Answer the question
In order to leave comments, you need to log in
How, after clicking on the submit in the form and processing the data on the server, redirect to another page and save these login and password in a cookie?
There is a login, after the user clicks submit, the data flies to the server and is processed (ajax), if everything is ok, then this button should direct me to another html page and save everything in cookies. How to implement this in code, who knows, write plz. (nodejs express)
Answer the question
In order to leave comments, you need to log in
on the client something like
jQuery.getJSON('/ajaxlogin/', {login:login, pass:pass}, function(result){
if (result.redirect) {
window.location = result.redirect
} else if (result.error) {
alert(result.error);
}
});
....
if (ok) {
return res.json({redirect: 'authorizationSuccess.html'})
} else {
return res.json({error: 'authorization fail!'})
}
....
Look towards Passport JS . If you use passport, the code in the router is something like this:
router.post('/auth',
passport.authenticate('local', {
successRedirect: '/user', //при удачной авторизации переадресовываем на страницу пользователя
failureRedirect: '/auth', //при неудаче, возвращаемся на страницу авторизации
failureFlash: true
})
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question