我試圖從以下版本獲取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