Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS http.get returns 404

I am trying to get a JSON from the openweathermap.org API using AngularJS, but my request returns an error code 404. Here is my code :

$scope.key = "XXXXXXXXXXXXX";

$scope.search = "Rouen";

$scope.url= "api.openweathermap.org/data/2.5/weather?q=" + $scope.search + "&APPID=" + $scope.key;

$scope.fetch = function(){
    $http.get($scope.url)
    .then(function(response){ 
       $scope.res = response.data;
       $scope.status= response.status;},
     function errorCallback(response) {
        alert(response.status);});

I have tried requesting another url, and got the same problem with this one : http://www.omdbapi.com/?t=Sherlock%20Holmes&tomatoes=true&plot=full

Does someone have an idea about what is wrong here ?

Forgive me if that is obvious, I am brand new in AngularJS and I haven't found any solution on other topics.

Thank you in advance for your answers !

like image 349
V. Déhaye Avatar asked Oct 29 '22 21:10

V. Déhaye


1 Answers

The only error I see is that you are not setting http:// before the url

this is the response on my chrome

Request URL:http://api.openweathermap.org/data/2.5/weather?q=Rouen&APPID=XXXXXXXXXXXXX
Request Method:GET
Status Code:401 Unauthorized
Remote Address:192.241.169.168:80

of course a 401 Unauthorized for the APPID not being valid

like image 69
pachonjcl Avatar answered Nov 11 '22 14:11

pachonjcl