无法阅读财产'结果'未定义的
角度函数:
.controller('forgotCtrl', function($scope,$http,$ionicPopup,$state,$ionicHistory) {
$scope.forgot=function(data1){
var link1 = 'http://localhost/uxo_data/forgot.php';
var json10 = {n : data1.mobile };
$http.post(link1, { data1: json10 })
.then(function (res){
$scope.response = res.data1.result;
console.log(res.data1.result);
if($scope.response.created=="1"){
$scope.title="Password Reset!";
$scope.template="Please Check your associated Email Account!";
//no back option
$ionicHistory.nextViewOptions({
disableAnimate: true,
disableBack: true
});
$state.go('login', {}, {location: "replace", reload: true});
}else if($scope.response.exists=="1"){
$scope.title="Failed";
$scope.template="Number you entered doesn't exist";
}else{
$scope.title="Failed";
$scope.template="Contact Our Technical Team";
}
var alertPopup = $ionicPopup.alert({
title: $scope.title,
template: $scope.template
});
});
}
})
我从rest-api获得的输出是:
{"result":{"created": "0" , "exists": "1" }}
我在Web调试工具中检查过,php代码工作正常,并将上面的响应作为输出。
答案 0 :(得分:1)
从
更改此行 $scope.response = res.data1.result;
到
$scope.response = res.data.result;
响应将包含您正在访问的数据对象。
答案 1 :(得分:1)
console.log(res.data1.result); // => data1 is undefined
尝试以下代码:
console.log(res.data.result);