0

我试图通过 AngularJS 从 BTC Guild API 获取一些基本信息,但它所做的只是在错误函数中运行,并且没有给出关于错误是什么的输出。Firebug 在中断该函数时在错误对象中不显示任何内容。有任何想法吗?

jsfiddle 链接:http: //jsfiddle.net/bX3ar/11/

javascript:

angular.module('BTCGuild', []);

function BTCGuildCtrl($scope, $http) {
    $http.get('https://www.btcguild.com/api.php?api_key=').success(function (response) {
        $scope.error = 'response:' + response;
        $scope.unpaidRewards = response.user.unpaid_rewards;
    }).error(function (error, status) {
        $scope.error = 'error:' + error + status;
    });
}

html:

<!doctype html>
<head>
    <script type="text/javascript" src="http://code.angularjs.org/1.1.5/angular.min.js"></script>
    <script type="text/javascript" src="btcguild.js"></script>
</head>
<html ng-app="BTCGuild">
<body>
    <div ng-controller="BTCGuildCtrl">
        <table>
            <p>{{unpaidRewards}}</p>
            <p>Error:{{error}}</p>
        </table>
    </div>
</body>
</html>
4

1 回答 1

0

几点注意事项:

  1. 您将收到“跨源请求”错误。这是修复后的响应片段: OPTIONS https://www.btcguild.com/api.php?api_key= No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://fiddle.jshell.net' is therefore not allowed access.
  2. 看看这些关于如何正确格式化 Angular 的 JSFiddle 的注释:框架和扩展应该是No Library - pure JSNo wrap, in。此外,您需要将其放在Fiddle Options: Body Tag下 <body ng-app="BTCGuild">
  3. 这是更新的 JSFiddle:http: //jsfiddle.net/bX3ar/14/

如果您可以解决 CORs 问题,您将看到这项工作。或者如果你放入一个 fake response,你可以看到它正确显示。

于 2014-02-09T00:05:58.283 回答