Reading a JSON by http in Angularjs does not work

Asked

Viewed 54 times

2

Hello I’m trying to read a JSON via http using Angularjs (I must use Angularjs) and I can’t even display the first JSON data because it doesn’t have a string that I can call in Function(Answer) in $Scope.countries = Answer. ? don’t know how to call the dice if they don’t have a string.

I can’t change the JSON data because it comes from a database that I can’t edit and I can’t read by embedding the data directly in js, it has to come from http.

My js and html:

var app = angular.module('MyApp', []);

app.controller('ArqCtrl', function($scope, $http) {
    $http.get("https://endereco.json").success(function(response) {
        $scope.countries = response.''  ;
    });
});
<!DOCTYPE html>
<html ng-app="MyApp">
<head>
    <meta charset="utf-8">
    <title>Test for archive</title>
</head>
<body>

    <div ng-controller="ArqCtrl">
        <ul>
            <li ng-repeat="country in countries">

                {{ country.name + ',' + country.capital + ',' + country.bd + ',' + country.pop }}
            </li>
        </ul>
    </div>
</body>
    
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js"></script>
    <script src="script.js"></script>
</html>

The JSON on the address has the data:

[{"name":"United States","capital":"Washington, D.C.","pop":321645000,"latlng":[38.0,-97.0],"bd":["CAN","MEX"]}]

If anyone can help, thank you

  • what comes in Sponse.data ?

  • Nothing @Levyhnunes, already put Sponse.data but returns nothing. :(

  • You may be having Cors errors

  • check tbm for any error in the console

  • First, you don’t go to a json directly from the https:/root, you must have a domain or website before, try to access the address manually and see what’s coming: https://endereco.json, I usually use ServiceNome.RequestData(params).then(function(result) { ... }); to bring the data. You can use the Postman to test the request.

  • test use: JSON.parse(result)

  • Look, I I made an example here just to illustrate this.

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.