I just started messing around with the lastfm API and I’m not sure why the response from chart.getlovedtracks is coming back undefined, using this code:
$(document).ready(function(){
var apiKey = "myapikey";
$.getJSON('http://ws.audioscrobbler.com/2.0/?method=chart.getlovedtracks&api_key='+ apiKey +'&format=json&callback=?',
function(data) {
console.log('Fetched ' + data.length + ' items!');
});
});
Am I missing something, seems pretty simple.
You should not be including the
callbackparameter unless you intend to use a callback function.You were also not parsing the JSON as expected. You can get the number of tracks returned with
data.tracks.track.length.This code works: