1

Trying to make an API call.

var app = angular.module("testApp", []);
app.controller("mCtrl", ["$scope", "$http", function($scope, $http) {
  $http.jsonp("api.openweathermap.org/data/2.5/weather?q=London,uk&APPID={APIKEY}")
       .success(function(data) {
          $scope.data = data;
          console.log($scope.data);

       });
}]);

Keep getting a 404 response. I can access the data when using the address in the browser though.

Znowman
  • 385
  • 1
  • 5
  • 19
  • This might be useful http://stackoverflow.com/questions/12066002/parsing-jsonp-http-jsonp-response-in-angular-js – Nathan Beck Oct 11 '16 at 19:31
  • Are you just missing `http://` in the request url? Check the browsers debugger tools (net/network tab) to see where that request is going. My bet would be to it's treating it as a relative url to the local server/domain. – AndrewR Oct 11 '16 at 19:38
  • You forgot the `http://`. Also, you probably should remove your API Key from public pages. – Gillespie Oct 11 '16 at 19:40

1 Answers1

1

First, you should be using $http.get('...') instead of $http.jsonp('...')

And second you forgot to add 'http://...' to the route

The correct way is

$http.get("http://api.openweathermap.org/data/2.5/weather?q=London,uk&APPID=d21b99023992fadfa586d8c3589d0b8d")
  .then(function(data) {
    $scope.data = data;
    console.log($scope.data);
  });

I've tested it, it should work

Mockingguy
  • 113
  • 9
  • Worked, ty, but why not jsonp? – Znowman Oct 11 '16 at 19:48
  • While you could technically use it, is more of a hassle and you only need a simple get, the [documentation](https://docs.angularjs.org/api/ng/service/$http#jsonp) tells you how but is not worth it. – Mockingguy Oct 11 '16 at 19:53