我试图从以下版本获取json数据: http://api.dailymile.com/entries.json 然后我希望在表格中显示这些数据。以下代码在json链接指向我的计算机上的文件时起作用,但在引用URL时不起作用。从.json URL获取数据并使用Javascript/JQuery以HTML格式显示
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>
<script>
$(function() {
var entries = [];
var dmJSON = "http://api.dailymile.com/entries.json";
$.getJSON(dmJSON, function(data) {
$.each(data.entries, function(i, f) {
var tblRow = "<tr>" + "<td>" + f.id + "</td>" + "<td>" + f.user.username + "</td>" + "<td>" + f.message + "</td>" + "<td> " + f.location + "</td>" + "<td>" + f.at + "</td>" + "</tr>"
$(tblRow).appendTo("#entrydata tbody");
});
});
});
</script>
</head>
<body>
<div class="wrapper">
<div class="profile">
<table id= "entrydata" border="1">
<thead>
<th>ID</th>
<th>UserName</th>
<th>Message</th>
<th>Location</th>
<th>Time</th>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</body>
</html>
任何帮助,为什么它不会加载JSON数据表示赞赏。
问题不应被删除后,他们已被回答,有人可能会遇到同样的问题,并从帖子中受益。 – apaul
不要因为解决问题而破坏或删除问题。 – Flexo