Вопрос

Could someone please run this code on their localhost, I have been trying to figure out why the first GET returns an empty response and the second GET returns expected response but indicates its malformed. Any help would be greatly appreciated.

<!DOCTYPE html>
<html lang="en-gb" ng-app="app">
<body>
  <div ng-controller="mainController"></div>

  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js"></script>
  <script>
    var app = angular.module('app',[]).controller('mainController', function($scope, $http){

    $scope.baseUrl = "http://api.nestoria.co.uk/api?action=echo&encoding=json&foo=bar";
    //$scope.baseUrl = 'http://www.iNorthwind.com/Service1.svc/getAllCustomers';

    // Works but no response content
    $http({method: 'GET', url: $scope.baseUrl})
     .success(function(data,status){
      console.log( data);
     });

    // Works but console states malformed jsonp, but has response content.      
   $http({method: 'jsonp', url: $scope.baseUrl + "&callback=JSON_CALLBACK'})
     .success(function(data,status){
      console.log( data);
    });   
  });
 </script>
</body>
</html>

Thanks

Это было полезно?

Решение

On the second one you have a mismatched quotation after CALLBACK

   $http({method: 'jsonp', url: $scope.baseUrl + "&callback=JSON_CALLBACK"})
     .success(function(data,status){
      console.log( data);
    });   
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top