我正在使用ajax调用来执行服务文件中的功能,如果响应成功,我想将页面重定向到另一个URL.目前,我通过使用简单的js"window.location = response ['message'];"来做到这一点.但我需要用angularjs代码替换它.我在stackoverflow上看了各种解决方案,他们使用了$ location.但我是棱角分明并且很难实现它.
$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
})
Run Code Online (Sandbox Code Playgroud)