0

Im really confused on how to load external resource with $http.jsonp. Here is my code:

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="customersCtrl"> 

<ul>
{{myData}}
</ul>

</div>

<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
var url = "https://angularjs.org/greet.php?callback=JSON_CALLBACK&name=Super%20Hero";
  $http.jsonp(url).then(function (response) {
      $scope.myData = response.data;
  });
});
</script>

</body>
</html>

And i got error like this:

Error: [$sce:insecurl]

Whats wrong with my code? Thank you.

hfbchri
  • 13
  • 1
  • 7
  • Have a look at these two links. 1. Explains why this happens[https://docs.angularjs.org/error/$sce/insecurl] 2. A solution[https://stackoverflow.com/questions/21292114/external-resource-not-being-loaded-by-angularjs] – Kavindra Dec 04 '17 at 03:39

1 Answers1

0

Working fine by updating your angular version from 1.6.4 to 1.2.6

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
var url = "https://angularjs.org/greet.php?callback=JSON_CALLBACK&name=Super%20Hero";
  $http.jsonp(url).then(function (response) {
  console.log(response)
      $scope.myData = response.data;
      
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl"></div>
jitender
  • 10,238
  • 1
  • 18
  • 44