Pregunta

In a nutshell, I'd like to display the Last.fm user playcount figure on my site (see 'playcount' on http://www.last.fm/api/show/user.getInfo). I've tried the following, but confess I have no idea if I'm on the right lines here.

$(document).ready(function() {
$.getJSON("http://ws.audioscrobbler.com/2.0/?method=user.getinfo&user=XXX&api_key=XXX&limit=5&format=json&callback=?", function(data) {
    var html = '';
    $.each(data.user.playcount, function(i, item) {
        html += "<p>" + item.playcount + "</p>";
    });
    $('#count').append(html);
});
});
¿Fue útil?

Solución

The inner foreach loop is unnecessary, user.getInfo returns only one user's information after all. The following should work:

$(document).ready(function() {
$.getJSON("http://ws.audioscrobbler.com/2.0/?method=user.getInfo&user=XXX&api_key=XXX&format=json", function(data) {
    var html = "<p>" + data.user.playcount + "</p>";
    $('#count').append(html);
});
});

I have also removed the limit and callback parameters from the URL for brevity.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top