我试图通过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>
答案 0 :(得分:0)
几点说明:
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.
<body ng-app="BTCGuild">
如果你能解决CORs问题,你会看到这项工作。或者,如果你输入假的response
,你可以看到它正确显示。