albpower
albpower

Reputation: 119

$http get returns not found,while the direct request works good

I am trying to use one webAPI coded in ASP.net but when I try to get data from that API using angular $http.get at the browser console I get GET <--URL--> Not found When I try to make requests to the same URL directly it works fine and returns data to me. I tried to add .json mimetype at Web.config in the ASP project but still same result.

The working url is: https://adaba.azurewebsites.net/api/flights/searchairports?name=london - note that it's a GET request with a required parameter so you need to pass a parameter to get something.

Here you can execute directly the api request from this Codepen: http://codepen.io/albpower/pen/mVgyNP

JS file:

var app = angular.module("APP",[]);

app.controller("appCtrl",function($http,$scope){
  $scope.calculate = function(){
    $http.get('http://adaba.azurewebsites.net/api/flights/searchairports',{
      name: $scope.input
    }).then(function (resp) {
     console.log(resp);
      $scope.response = resp;
  });
  }
})

HTML file:

<div ng-app="APP" ng-controller="appCtrl">
  <input type="text" placeholder="amount" ng-model="input"><br><br>

  <button ng-click="calculate()">Calculate</button>

  <pre>
  {{response | json}}
  </pre>
</div>

Upvotes: 0

Views: 584

Answers (1)

Johannes Jander
Johannes Jander

Reputation: 5020

You issue is:

  • you are not setting the parameters for the request correctly, you need to do this with the params property

The code should be:

 $http.get('https://adaba.azurewebsites.net/api/flights/searchairports',{
      params: {name: $scope.input}
 }).then(function (resp) {

See here: http://codepen.io/anon/pen/OMGpqX

Oh, and please use https://

Upvotes: 2

Related Questions