Question

I'm new in using JSON with Jquery and i ret some documentation and still cant get it to work. I need pase data using JSON from last.fm API and get artist information (summary).

Link to API with artist Cher: http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Cher&api_key=2b35547bd5675d8ecb2b911ee9901f59&format=json

Can anybody experienced write me simple example how to use Jquery to get an artist information from last.fm ? Thank you in advance :)

Was it helpful?

Solution

You could start with something like

$.ajax({
  url: 'http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Cher&api_key=2b35547bd5675d8ecb2b911ee9901f59&format=json',
  success: function(data) {
    alert(data.artist.name);
  }
})

As you can see data is in json format, so you could access its properties using the dot notation.

OTHER TIPS

Before asking, you should make a little Google search!

$.getJSON('http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Cher&api_key=2b35547bd5675d8ecb2b911ee9901f59&format=json', function(data) {
    var items = [];

    $.each(data, function(key, val) {
      items.push('<li id="' + key + '">' + val + '</li>');
    });

    $('<ul/>', {
      'class': 'my-new-list',
      html: items.join('')
    }).appendTo('body');
});

Directly from jQuery.getJSON -- read documentation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top