Javascript 从angularjs将登录页面重定向到欢迎页面
我正在创建的web应用程序中,如果我的用户id和密码经过验证,我需要从登录重定向到欢迎页面Javascript 从angularjs将登录页面重定向到欢迎页面,javascript,angularjs,asp.net-mvc-5,Javascript,Angularjs,Asp.net Mvc 5,我正在创建的web应用程序中,如果我的用户id和密码经过验证,我需要从登录重定向到欢迎页面 <script> var app = angular.module('myApp', []); app.controller('customersCtrl', function ($scope, $http, $interval) { //login $scope.loginbutton = function () {
<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function ($scope, $http, $interval) {
//login
$scope.loginbutton = function () {
$http.get('/login.asmx/loginuser', {
params: {
log: $scope.log,
pm: $scope.pm,
password: $scope.password
}
})
.then(function (response) {
{
//here i want to redirect to another page
}
})
}
});
</script>
var-app=angular.module('myApp',[]);
app.controller('customersCtrl',函数($scope,$http,$interval){
//登录
$scope.loginbutton=函数(){
$http.get('/login.asmx/loginuser'{
参数:{
日志:$scope.log,
下午:$scope.pm,
密码:$scope.password
}
})
.然后(功能(响应){
{
//这里我想重定向到另一个页面
}
})
}
});
这是我的angularjs脚本,我如何将页面重定向到另一个页面?您可以使用$location服务,例如:
<br>$location.path('/home')<br>
$location.path('/home')
以下是参考guid以了解更多信息
<script>
var app = angular.module('myApp', ['$location']);
app.controller('customersCtrl', function ($scope, $http, $interval, $location) { // add $location dependency in the
//login
$scope.loginbutton = function () {
$http.get('/login.asmx/loginuser', {
params: {
log: $scope.log,
pm: $scope.pm,
password: $scope.password
}
})
.then(function (response) {
{
$location.path('google.com') //pass the url in it.
}
})
}
});
</script>
var app=angular.module('myApp',['$location']);
controller('customersCtrl',function($scope、$http、$interval、$location){//在
//登录
$scope.loginbutton=函数(){
$http.get('/login.asmx/loginuser'{
参数:{
日志:$scope.log,
下午:$scope.pm,
密码:$scope.password
}
})
.然后(功能(响应){
{
$location.path('google.com')//在其中传递url。
}
})
}
});
使用$state
重定向
controller.js
controller('customersCtrl', function ($scope, $http, $interval, $state) {
$scope.loginbutton = function () {
$http.get('/login.asmx/loginuser', {
params: {
log: $scope.log,
pm: $scope.pm,
password: $scope.password
}
})
.then(function (response) {
$state.go('page');
})
}
});
然后在route.js中,您需要指定要重定向到的新状态
angular.module('app.routes', []);
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('page', {
url: '/page',
templateUrl: 'templates/page.html',
controller: 'pageCtrl'
})
});
您需要在控制器中包含
$location
依赖项,并且需要调用$location.url('/login')
导航到登录页面。我已经为此修改了您的代码
<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function ($scope, $http, $interval, $location) {
//login
$scope.loginbutton = function () {
$http.get('/login.asmx/loginuser', {
params: {
log: $scope.log,
pm: $scope.pm,
password: $scope.password
}
})
.then(function (response) {
{
//Navigate to welcome page
$location.url('/welcome');
}
})
}
});
</script>
在控制器中添加$window
app.controller('customersCtrl', function ($scope, $http, $interval, $location, $window) {
然后在您的回复中添加以下行
.then(function (response) {
{
$window.location.href = "../welcome/Index";
}
})
.then(function (response) {
{
$window.location.href = "../welcome/Index";
}
})