如何使用Angular JS阅读Kickstarter json

时间:2014-10-07 07:17:56

标签: javascript arrays json angularjs kickstarter

我是一个尝试使用Angular JS来读取Kickstarter json数据并将其显示在页面上的新手。

我有一个代码笔,显示我使用的工作样本数据源的基本代码,然后是一个没有工作示例的启动源代码。

http://codepen.io/anon/pen/KmCsc

HTML

<div ng-app>
<div ng-controller="recent">
<p>First Project ID: {{kickstarter.projects[0].id}}</p>
<p>Total hits: {{kickstarter.total_hits}}</p>
</div>
</div>

的Javascript

function recent($scope, $http) {
$http.get('https://www.kickstarter.com/discover/recently-launched?format=json').
success(function(data) {
$scope.kickstarter = data;
});
}

我可能在如何引用变量时犯了一个错误,我已经将我的头撞在墙上好几个小时而且看不到它。非常感谢您的专业知识。

供参考Kickstarter最近的项目数据在这里以json格式提供:https://www.kickstarter.com/discover/recently-launched?format=json

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

你的例子有效。您正在发送请求,模型绑定应该工作。但是,如果您在控制台中查看,则会收到以下错误消息:XMLHttpRequest cannot load https://www.kickstarter.com/discover/recently-launched?format=json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://s.codepen.io' is therefore not allowed access.

查看this回答