res.redirect from POST
Aus irgendeinem Grund kann ich nicht zu / blog umleiten, sobald mein Login abgeschlossen ist. In meinem Login-Controller habe ich Folgendes.
module.exports = {
post: function(req, res) {
var login = req.body['login'];
if (login && req.body['login']['password'] == "password") {
console.log('Granted access');
res.send({redirect: '/blog'});
}
else {
console.log('wrong password');
res.redirect('back');
}
}
};
Die jquery Ajax
$(document).ready ->
$('#login-button').click () ->
$.ajax
url: '/login'
type: 'POST'
data: $('#Password').serialize()
dataType: 'json'
success: (data, textStatus, jqXHR) ->
if typeof data.redirect == 'string'
window.location = data.redirect
aktualisiert auf Arbeitscode