I recently redesigned my site and now I need to use dynamic AJAX requests for my data. Basically, I am trying to get user data using Last.FM API in JSON format.
I'm new to this, especially JSON, and it hurts a bit! I know that I am missing something simple.
Here is some very simple code to test the functionality, but it doesnβt extract anything!
<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>
Any suggestions?
I would like to be able to use the JSON object throughout the page so that, for example, at any time I can just call topartists.artist [i] .playcount; to display a playlist, etc. How can i do this?