【发布时间】:2015-03-12 13:46:15
【问题描述】:
我正在使用 ajax 调用在服务文件中执行功能,如果响应成功,我想将页面重定向到另一个 url。目前,我正在通过纯 JS 代码 window.location = response['message']; 执行此操作。但我需要用 AngularJS 代码替换它。我在 stackoverflow 上查看了各种解决方案,他们使用了$location。但我是 AngularJS 的新手,在实现它时遇到了麻烦。
$http({
url: RootURL+'app-code/common.service.php',
method: "POST",
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
dataType: 'json',
data:data + '&method=signin'
}).success(function (response) {
console.log(response);
if (response['code'] == '420') {
$scope.message = response['message'];
$scope.loginPassword = '';
}
else if (response['code'] != '200'){
$scope.message = response['message'];
$scope.loginPassword = '';
}
else {
window.location = response['message'];
}
// $scope.users = data.users; // assign $scope.persons here as promise is resolved here
})
【问题讨论】:
-
为什么需要使用 Angular 来实现?有什么具体原因吗? document.location 是正确的方式,可能比角度方式更有效
标签: javascript angularjs