我正在使用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
})