0

Where is the wrong because I did all for this work. Please, someone help me!

<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>  
  <script type="text/javascript">
    var app = angular.module('myApp', []);
    app.controller('heroisCtrl', function($scope, $http) {
       $http.get("https://angularjs.org/greet.php?callback=herois&name=Super%20Hero")
       .success(function(data) { $scope.names = data;});
    });
    </script>
</head>
<body>

<div ng-app="myApp" ng-controller="heroisCtrl">
<table>
  <tr ng-repeat="x in names">
    <td>{{ x.name }}</td>
    <td>{{ x.greeting }}</td>
  </tr>
</table>
</div>

</body>
</html>

At final I have this information by console: XMLHttpRequest cannot load angularjs.org/greet.php?callback=herois&name=Super%20Hero. No 'Access-Control-Allow-Origin' header is present on the requested resource.

1

2 Answers 2

1

When fatch data from call back api then must set callback=JSON_CALLBACK

<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>  
  <script type="text/javascript">
        var app = angular.module('myApp', []);
        app.controller('heroisCtrl', function($scope, $http) {
           $http.get("https://angularjs.org/greet.php?callback=JSON_CALLBACK&herois&name=Super%20Hero").success(function(data) { $scope.names = data;});
        });
    </script>
</head>
<body>

    <div ng-app="myApp" ng-controller="heroisCtrl">
        <table>
          <tr ng-repeat="x in names">
            <td>{{ x.name }}</td>
            <td>{{ x.greeting }}</td>
          </tr>
        </table>
    </div>

</body>
</html>
Sign up to request clarification or add additional context in comments.

2 Comments

Perfect Sandeep, but, How do I when need use other API, for example this: folhacar.com.br/frontendnovo.php/api/… Is not work. I'm using {{ x.nome_marca }} for print, but... is not working.
It's so simple... follow this code: $http.get("http://www.folhacar.com.br/frontendnovo.php/api/listMarcas?callback=JSON_CALLBACK").success(function(data) { $scope.names = data;});
0

this problem is your backend! You have to add

 AllowOrigin = '*' //not secure

Or add

AllowOrigin: 'yourClientAddressOrIp'

Not sure about sintax, but the idea is as i write before, then should be there. Sintax depends on your backend languaje.

And thats All

Regards

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.