javascriptjsonionic-frameworkapplication-icon

Issues retrieving jsonp with $http.jsonp


Code:

When i past the url in the browser i can see all the objects when i try to it out on for example : link

but I don't seem it to get it working in my code am i missing anything ?

 angular.module('ionicApp', ['ionic'])

 .controller('MyCtrl', function($scope, $http) {

  $scope.items = [];



  $http.jsonp('cmaden.pythonanywhere.com/api/v1/today/?format=jsonp').success(function    (data) {
    $scope.items = data;

});

});

Solution

  • Add "https://" to the front of the url. You will also need a callback. Please see the example below.

    angular.module('ionicApp', ['ionic'])
     .controller('MyCtrl', function($scope, $http) {
     window.callback = function(data) {
          $scope.items = data
        }  
      $scope.items = [];
     $http.jsonp('https://cmaden.pythonanywhere.com/api/v1/today/?format=jsonp');  
    });