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.

3
  • This might be useful stackoverflow.com/questions/12066002/… Commented Oct 11, 2016 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. Commented Oct 11, 2016 at 19:38
  • You forgot the http://. Also, you probably should remove your API Key from public pages. Commented Oct 11, 2016 at 19:40

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Worked, ty, but why not jsonp?
While you could technically use it, is more of a hassle and you only need a simple get, the documentation tells you how but is not worth it.

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.