I am just calling api which returns josn encoded data and trying to print object property but shows undefined but when I print that object , the object has that property and value.
my code
function sendData(postData, url){
var response = apiCall(postData,url);
console.log(response.email)
console.log(response.count);
}
function apiCall(postData, postUrl){
var response = {};
$http({
method : 'POST',
url : postUrl,
data : postData,
headers : {'Content-Type': 'application/json'}
}).success(function(data) {
console.log(data)
for (var attr in data) {
if (data.hasOwnProperty(attr)) response[attr] = data[attr];
}
});
return response;
}
php based api
<?php
$_POST = json_decode(file_get_contents('php://input'), true);
$response = array();
$response['email'] = $_POST['oauth']['email'];
$response['type'] = $_POST['oauth']['type'];
echo json_encode($response);
?>
response data in console
Object {email: "sameerdighe14@gmail.com", type: "google"}