**JS Code**
Getting a problem in fetching JSON object value from php and displaying it in console.
我已经实现了一个post值方法,其中包含了用户的值,其中包含电子邮件和密码。在php文件中,我正在验证它并将值返回给json对象,但它没有显示任何值。
任何人都可以找到代码的错误。
我已将ggApp定义为我的body标签
var ggApp = angular.module('ggApp', []);
ggApp.controller('loginCtrl',function($scope,$http){
$scope.loginApp = function(user){
console.log(user);
$http.post('/getgrocers/cred_files/login.php', user).success(function(data){
console.log(data);
}).error(function(data){
console.log(data);
});
}
})
<div class="sign-in" ng-controller="loginCtrl">
<form method="post">
<input type="email" placeholder="Email Address" ng-model="user.email"/>
<input type="password" placeholder="Password" ng-model="user.pass"/>
<input type="submit" value="Log In" ng-click="loginApp(user)">
</form>
</div>
**PHP Code**
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
$userq = json_decode(file_get_contents("php://input"));
$data1 = "";
if($userq->email == "chandra****@gmail.com" && $userq->pass == "***"){
$data1 = "secess";
}
else
$data1 = "error";
}
$dd = json_encode($data1);
print_r($dd);
return json_encode($dd);
?>
答案 0 :(得分:0)
你应该echo
json而不是return
它并摆脱print_r
尝试更改:
$dd = json_encode($data1);
print_r($dd);
return json_encode($dd);
要
$dd = json_encode($data1);
echo json_encode($dd);