I am currently working on a personal project using Last FM's API to display data on my music tastes.
The first task I've given myself is to create a table which displays my Recently Played Tracks.
I'm using the DataTables plugin for JQuery as I want to refresh the table's data on the fly as I play more tunes using AJAX.
The JSON data returned by the Last FM API is a little messy so I'm using the JQuery Map method to create a new array of objects only containing the attributes I intend to use from the API.
Here's a fiddle of what I have so far:
http://jsfiddle.net/8rekuLaf/2/
However because I want to refresh the data as a new song plays I wonder whether I should remove the map stuff and populate my DataTable directly from AJAX. I've been unable to do this. Below is an example of one unsuccessful attempt:
config.recentTracksElement.dataTable({
"ajax": config.getRecentTracksURL,
"columns": [{
"data": "name"
}, {
"data": "artist.#text"
}, ]
});
Anyone who could show me how to use JSON from a URL with Datatables would be a great help. And also how to use AJAX reload to refresh the data.
Thanks