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
The backend get successfull the post request, but the redirect to the new page will not happen cause I´ve in the chrome console this error:
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
The backend get successfull the post request, but the redirect to the new page will not happen cause I´ve in the chrome console this error:
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');
});
Share
Improve this question
edited Jan 22, 2018 at 13:11
AA Shakil
5564 silver badges16 bronze badges
asked Jan 22, 2018 at 12:56
Lukas GundLukas Gund
7112 gold badges10 silver badges30 bronze badges
1 Answer
Reset to default 2You 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) {
...
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745651778a4638306.html
评论列表(0条)