我正在实现JavaScript身份验证,当用户成功登录时,我希望打开一些html文件。当用户输入用户名和密码时,我向正在验证用户凭据的服务器发送ajax请求。如果验证成功,我会向注册路由(“仪表板”)发送另一个ajax请求。作为ajax请求的响应,我有整个html页面代码。如何在注册的路由(在我的情况下是仪表板)上呈现此代码?
这是我的密码
客户端:
$.ajax({
url: "signinUser",
method: "GET",
headers: {"Authorization": "Basic " + btoa(name + ":" + pass)},
success: function(result) {
$.ajax({
url: "dashboard",
method: "GET",
success: function(result) {
console.log(result);
}
});
}
}); 服务器:
app.get('/dashboard', function (req, res) {
res.sendFile(path.join(__dirname+'/dashboard.html'));
});发布于 2016-10-17 21:49:53
用这个:
document.location.href = '/dashboard';就你的具体情况而言:
$.ajax({
url: "signinUser",
method: "GET",
headers: {"Authorization": "Basic " + btoa(name + ":" + pass)},
success: function(result) {
document.location.href = '/dashboard';
// or
/* document.location.href = result.url; // for dynamic redirect */
}
});https://stackoverflow.com/questions/40095258
复制相似问题