【发布时间】:2018-07-18 07:56:50
【问题描述】:
如果用户名正确,我想从 login.html 重定向到 dashboard.html,如果不正确,则会显示警告框,我使用 express response.redirect('path') 或 response.sendFile('path') 但是没有人在这里工作。 我使用 angularJs 作为前端,在后端使用 nodeJs 的 express 模块。
快递路线代码:
module.exports = function(app,db,path){
app.post('/student-login', function (request, response) {
var user = request.body;
if(user.username == "abhinav")
{
response.redirect('/views/dashboard.html');
response.end();
}
else{
response.send("Wrong username");
response.end();
}
});
}
AngularJs 代码:
angular.module('loginService',[])
.service('loginService',function($http){
return {
sendStudent : function(data){
return $http.post('/student-login',data)
.then(function(response){
return response.data;
});
}
}
});
AngularJs 控制器代码:
if ($scope.myForm.$valid)
loginService.sendStudent($scope.studentData)
.then(function(data){
if(data=="Wrong username")
alert(data);
});
【问题讨论】: