I wanted to implement redirection after getting successful response from server. I tried to do it the same way as described here, but unfortunately couldn't achieve the desired behavior.
The function which sends the data to the server and is supposed to perform redirection is the following:
$("#btn-login").click(function(){
if ($('#loginform').valid() == false) {
return false;
}
var formData = $("form#loginform").serialize();
$.ajax({
type: "POST",
url: "/authentication/login",
data: formData,
success: function(data, textStatus){
console.log(formData);
//console.log(data);
if(data.redirect){
window.location.href = data.redirect;
}
},
error: function(e){
alert(e.responseText);
}
});
});
On the server side, the followoing function is executed:
/* Handle Login POST */
router.post('/login', passport.authenticate('login', {
successRedirect: '/',
failureRedirect: '/authentication',
failureFlash : true
}));
Does anyone know why the function on client does not redirect after receiving response from the server?
Thanks!