[英]How to fix? Chrome console : ERR_UNSAFE_REDIRECT
Post request webserver to the nodejs backend: 将请求Web服务器发布到nodejs后端:
$('#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
POST http:// localhost:1000 /登录网:: ERR_UNSAFE_REDIRECT
I know this is not a protected SSL connection. 我知道这不是受保护的SSL连接。 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
: 您正在发送对ajax请求的重定向响应,为什么不让javascript通过使用
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: 请注意,如果希望上面的示例起作用,则应定义
/dashboard
路线:
app.get('/dashboard', function(req, res) {
...
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.