1
Hello I’m looking for information in a local database with the following code:
var app = angular.module('app',[]);
app.controller('conexao',function($scope, $http){
$scope.names = [];
$http.get('http://localhost/angular/conect/connect.php').then(function successCalback(response){
$scope.names = response.data;
console.log($scope.names);
},
function errorCallback(response){
console.error('Erro ' + response);
});
});
To be displayed here:
<body ng-controller="conexao">
<table>
<tr ng-repeat="x in names">
<td>{{x.nome}}</td>
<td>{{x.idade}}</td>
<td>{{x.cor}}</td>
</tr>
</table>
</body>
But all I get is an empty screen, although the console returns me:
>Object {records: Array[2]}
And then that message:
Synchronous Xmlhttprequest on the main thread is deprecated because of its detrimental effects to the end user’s Experience.
I want to understand what’s going on and know how to fix it.
Using this form it returns: [Object, Object]. As for the other topic I’m trying to understand the solutions, they seem to me vague. there are commenting from Jquery and I’m not using anything from Jquery here.
– Henrique Silva
Okay, focusing on the first problem. Still you couldn’t display? I put one more option in my answer, take a look.
– celsomtrindade
There’s still no answer. 'Response.data' returns: 'Object {Records: Array[2]}' 'Response.data.Records' returns: '[Object, Object]' Even when searching to add . Records in repeat does not change anything
– Henrique Silva
Does the data inside the 'Objects' match correctly to the ones you are trying to display? Get a console print with the 'Objects' open?
– celsomtrindade
It’s the data I really want, it’s the exact data I’m looking for from the BD. I’m going to put the image up there next to the question.
– Henrique Silva
Note that your Object has fields with the first uppercase letter. Change this in your html as well. x.Name, x.Age and x.Color =D
– celsomtrindade
It worked! o.0 kkkkkkk Can you explain to me why this happens? I have another example that make a get of an API and it works normally when I started using one . php gave this, I don’t know if it has to do, but all the settings I’ve made are in minuscules.
– Henrique Silva
There it would be because it is a case sensitive process, that is, if it is uppercase or lowercase, it makes a difference. Now about your other problem, I will provide a $http.get template that I use. I believe your problem is happening because you’re going through
url
complete in the process.– celsomtrindade
Nothing has changed with this change in $http.get this problem still persists. Everything I’m finding concerning this involves Jquery, but this is not my case, I’m not using Jquery.
– Henrique Silva
All I’m finding is about jQuery too. Now I’m running out of time, but I’ll see if I can get an answer for you on that.
– celsomtrindade