-2
I’m just trying to get a return value HTTP
but I’m not getting it.
.controller('myCtrl', function ($scope, $http) {
$scope.sendPost = function() {
var dataObj = {
name : $scope.newName
};
var res = $http.post('xxxx.consulta.php', dataObj)
res.success(function(data, status, headers, config) {
$scope.hello = data;
});
}
})
When I run the page in the browser it returns the object to me JSON
:
[{"id":"13","nome":"Yuri","departamento":"EAD","img":"https:\/\/image.freepik.com\/icones-gratis\/perfil-macho-utilizador-sombra_318-40244.png"}]
Would you like to save only id and name, how do I do? I have tried
data.id
or in the view
{{hello.id}}
and it didn’t work...
Try this:
$scope.hello = data.data
– celsomtrindade
Didn’t work...
– Yuri Rodrigues
use
console.log(data)
inside the Success, which it shows on your console?– celsomtrindade
[Object] 0: Object departamento: "EAD" id: "13" img: "https://image.freepik.com/icones-gratis/perfil-macho-utilizador-sombra_318-40244.png" nome: "Yuri" proto: Object length: 1 proto: Array[0]
– Yuri Rodrigues
And if you do so:
= data[0]
?– celsomtrindade
It worked like this, but I believe that is not so...pq will have several array in a query, so I will only take one...
– Yuri Rodrigues
to do so You would need to loop the array, I will add response
– celsomtrindade