一個JSON對象,我最近改變了我的網站設計,現在需要使用動態AJAX請求我的數據。基本上,我試圖使用JSON格式的Last.FM API檢索用戶數據。
我新望這一點,特別是JSON,和它給了我一個有點頭疼!我知道我必須錯過簡單的事情。
下面是一些非常基本的代碼來測試功能,但它沒有任何檢索!
<html>
<head>
<script src="./jquery/jquery-1.4.4.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function() {
$.getJSON("http://ws.audioscrobbler.com/2.0/?method=user.getTopArtists&user=test&api_key=690e1ed3bc00bc91804cd8f7fe5ed6d4&limit=5&format=json&callback=?", function(data) {
$.each(data.topartists.artist, function(i,item){
html += "<p>" + item.name + " - " + item.playcount + "</p>";
});
$('#test').append(html);
});
});
</script>
<div id="test"></div>
</body></html>
有什麼建議嗎?
我想能夠使用JSON對象在整個頁面,這樣,例如,在任何時候我可以叫topartists.artist [I] .playcount;顯示playcount等。我該怎麼做?
http://jsfiddle.net/eSv9x/ – Val 2011-02-24 10:37:52