I'm creating a small music suggestion website using the LastFM API. I've succesfully set up the search function, where people can enter an artist they like and get back one that is similar (using this http://www.last.fm/api/show/artist.getSimilar).
function getSimilar(){
var search = $('#search').val();
var url = 'http://ws.audioscrobbler.com/2.0/?method=artist.getsimilar&artist=' + search +'&api_key=ac83636465b06e3626587c01f7d85bba&format=json';
$.get(url, function(response){
var similar = response.similarartists.artist[0].name;
var image = response.similarartists.artist[0].image[2]['#text'];
$('#result').html(similar);
$('#result2').html("<img src='"+image+"'>");
})
};
// Run function on click
$('#submit').click(getSimilar);
However, I also want to include a summary of the artist alongside the name (http://www.last.fm/api/show/artist.getInfo). The actual API call seems to be working... when I enter an artist name in the url where +similar+ currently is it loads the summary for that artist, but of course I want the bio for the artist that actually comes up for the user! Here is the code:
// Get info
function getInfo(){
var infourl = 'http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist='+ similar +'&api_key=ac83636465b06e3626587c01f7d85bba&format=json'
$.get(infourl, function(response){
var info = response.artist.bio.summary;
$('#result3').html(info);
})
};
//Run function on click
$('#submit').click(getInfo);
I'm still learning about APIs and JQuery, so I would be extremely grateful for any guidance on where I have gone wrong. Thank you :)