我正在开发我的前端(Angular Js 调用 Rest 服务),这工作正常,我得到了一个很好的 JSON 作为响应:
$scope.test = function(response) {
$http.get("http://localhost:8080/androbridge/test/dotest"+"?s=ssss").success(function(response){
$scope.related=JSON.stringify(response);
});
虽然这不起作用:
var x;
$http.get("http://localhost:8080/androbridge/einloggen/loggeEin?username=" + $scope.username + "&password=" + $scope.password).success(function(response)
{x=JSON.stringify(response);})
if(x=={"Kennzeichnung":"login","Status":true}){
$rootScope.loggedIn=true;
$location.path('/userPage');
}else {
alert('Wrong Login Information'+$scope.username +$scope.password + x)
}
有人看到我犯了什么错误吗?我想不通!
最佳答案
首先,你不能像这样进行对象比较:
if(x=={"Kennzeichnung":"登录","状态":true}){
你可以这样做:
if(x.Kennzeichnung == '登录' && x.Status){
此外,$http.success()
方法已被弃用。您应该使用 $http().then(successFn, errorFn);
代替。
关于javascript - AngularJS Rest GET 请求不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33654546/