AngularJS的BTC Guild API解析问题

时间:2013-08-13 15:55:25

标签: angularjs bitcoin

我试图通过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>

1 个答案:

答案 0 :(得分:0)

几点说明:

  1. 您将收到“Cross Origin Request”错误。这是修复后的响应片段: 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. Take a look at these notes on how to properly format a JSFiddle for Angular:框架&amp;扩展名应为 No Library - pure JS No wrap,in 。此外,您还需要将其放在小提琴选项:正文标记 <body ng-app="BTCGuild">
  3. 这是更新后的JSFiddle:http://jsfiddle.net/bX3ar/14/
  4. 如果你能解决CORs问题,你会看到这项工作。或者,如果你输入假的response,你可以看到它正确显示。