Post request webserver to the nodejs backend:
$('#login').click(function() {
$.post(
'/login',
{
mail: encodeURIComponent($('#mail').val()),
password: encodeURIComponent($('#password').val())
},
function(result) {
console.log(result);
});
});
Problem
POST http://localhost:1000/login net::ERR_UNSAFE_REDIRECT
I know this is not a protected SSL connection. But is there a way to fix it? Or did I made some settings wrong?
Code I´ve in the backend:
app.post('/login', function(req, res) {
console.log(req.body);
res.redirect(__dirname+'/wwwroot/views/profile/dashboard.html');
});
Post request webserver to the nodejs backend:
$('#login').click(function() {
$.post(
'/login',
{
mail: encodeURIComponent($('#mail').val()),
password: encodeURIComponent($('#password').val())
},
function(result) {
console.log(result);
});
});
Problem
POST http://localhost:1000/login net::ERR_UNSAFE_REDIRECT
I know this is not a protected SSL connection. But is there a way to fix it? Or did I made some settings wrong?
Code I´ve in the backend:
app.post('/login', function(req, res) {
console.log(req.body);
res.redirect(__dirname+'/wwwroot/views/profile/dashboard.html');
});
You are sending a redirect response to ajax request, why not just let javascript do the redirect for you by using window.location.href
:
Server:
app.post('/login', function(req, res) {
console.log(req.body);
res.json({ success: true });
});
Client:
$('#login').click(function() {
$.post(
'/login',
{
mail: encodeURIComponent($('#mail').val()),
password: encodeURIComponent($('#password').val())
},
function(result) {
if (result.success) {
window.location.href = '/dashboard'
}
});
});
Note that you should define /dashboard
route if you want the example above works:
app.get('/dashboard', function(req, res) {
...
});