繁体   English   中英

Angular.JS $ http API请求

[英]Angular.JS $http API request

我有一个奇怪的问题。 到处都是,但找不到任何解决方案。 这是我第一次使用angular.js,我正在尝试将API中的内容添加到我的Angular App中。

成功消息有效,但(数据)为空。 如果我将GET URL从w3Schools http://www.w3schools.com/website/Customers_JSON.php更改为一个,则它可以工作。 因此,我不确定我的请求网址http://fingerzeig.ch/api/agenda/list的格式是否正确,我也不知道是否需要解码或编码数据。 如果我比较两个页面,我会发现fingerzeig URL有点不同。

任何帮助,将不胜感激。

这是我的代码myapp.js:

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

app.controller("PostsCtrl", function($scope, $http) {
  $http.get('http://fingerzeig.ch/api/agenda/list').
    success(function(data, status, headers, config) {
     console.log("success!");
     console.log(data);
      $scope.posts = data;
    }).
    error(function(data, status, headers, config) {
      // log error
    });
});

HTML:

<body ng-app="MyApp">
              <div ng-controller="PostsCtrl">
                <ul ng-repeat="post in posts">
                  <li>{{post.ID}}</li>
                </ul>
            </div>
</body>

这里的链接:

http://www.w3schools.com/website/Customers_JSON.php =>工作

http://fingerzeig.ch/api/agenda/list =>不起作用

这些是杂项:一个带有我要工作的请求URL。 一种带有来自w3学校的示例url。 仅GET网址被更改。

小提琴无法正常工作: 链接

一个工作的人链接

非常感谢你!

这可能是一个跨域问题。 请注意, http://www.w3schools.com/website/Customers_JSON.php具有Access-Control-Allow-Origin: *响应标头,而http://fingerzeig.ch/api/agenda/list没有。

$ curl -I "http://www.w3schools.com/website/Customers_JSON.php"

如果您要发出跨域请求,则必须处理CORS。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM