0

我不想通过从Grooveshark中获取的 tinysong API 获取歌曲列表,我正在通过它进行操作$.ajax,到目前为止我得到了这个:

$.ajax({
    url : 'http://tinysong.com/s/Beethoven?format=json&key='+key,
    type : 'get',
    dataType : 'jsonp',
    succes : function(response){
        console.log(response);
        $('.content').append(response);
    },
    error: function(error){
        console.warn('ERROR');
        console.warn(error);
    }
});

key他们分配给我的 API 密钥在哪里。我收到以下错误:

资源解释为脚本,但使用 MIME 类型 text/html 传输:“http://tinysong.com/s/Beethoven?format=json&key=HERE_IS_MY_KEY&callback=jQuery172021696692402474582_1344209008518&_=1344209008523”。

但是,如果我转到该网址,我确实会打印出如下结果:

[{"Url":"http://tinysong.com/Aoxo","SongID":25802452,"SongName":"A 大调第七交响曲 Op. 92: Allegretto","ArtistID":1833, "ArtistName":"Beethoven","AlbumID":4497124,"AlbumName":"Beethoven: 9 Symphonien, Ouvert\u00fcren (1 of 6), Berstein, Leonard"},{"Url":"http://tinysong .com/jh4X","SongID":2909282,"SongName":"降E大调第五钢琴协奏曲 op. 73 'Emperor'","ArtistID":1833,"ArtistName":"Beethoven","AlbumID ":268605,"AlbumName":"The Best of Beethoven"},{"Url":"http://tinysong.com/JhLy","SongID":31825464,"SongName":"Beethoven: Piano Sonata #23 F小调,作品57,\"Appassionata\"","ArtistID":1833,"ArtistName":"Beethoven","AlbumID":4913792,"AlbumName":"Beethoven's Greatest Hits"},{"Url":"http://tinysong.com/ 6Jk1","SongID":4925300,"SongName":"Beethoven #4: Adagio","ArtistID":1833,"ArtistName":"Beethoven","AlbumID":842118,"AlbumName":"Beethoven: Symphonies Nos . 7 & 4"},{"Url":"http://tinysong.com/gGW0","SongID":11896153,"SongName":"F\u00fcr Elise","ArtistID":1833,"ArtistName" :"Beethoven","AlbumID":2087629,"AlbumName":"Beethoven and the Sea"}]"Beethoven","AlbumID":4913792,"AlbumName":"Beethoven's Greatest Hits"},{"Url":"http://tinysong.com/6Jk1","SongID":4925300,"SongName":"Beethoven #4: Adagio","ArtistID":1833,"ArtistName":"Beethoven","AlbumID":842118,"AlbumName":"Beethoven: Symphonies Nos. 7 & 4"},{"Url":"http: //tinysong.com/gGW0","SongID":11896153,"SongName":"F\u00fcr Elise","ArtistID":1833,"ArtistName":"Beethoven","AlbumID":2087629,"AlbumName": 《贝多芬与海》}]"Beethoven","AlbumID":4913792,"AlbumName":"Beethoven's Greatest Hits"},{"Url":"http://tinysong.com/6Jk1","SongID":4925300,"SongName":"Beethoven #4: Adagio","ArtistID":1833,"ArtistName":"Beethoven","AlbumID":842118,"AlbumName":"Beethoven: Symphonies Nos. 7 & 4"},{"Url":"http: //tinysong.com/gGW0","SongID":11896153,"SongName":"F\u00fcr Elise","ArtistID":1833,"ArtistName":"Beethoven","AlbumID":2087629,"AlbumName": 《贝多芬与海》}]com/6Jk1","SongID":4925300,"SongName":"Beethoven #4: Adagio","ArtistID":1833,"ArtistName":"Beethoven","AlbumID":842118,"AlbumName":"Beethoven:第 7 和 4 号交响曲"},{"Url":"http://tinysong.com/gGW0","SongID":11896153,"SongName":"F\u00fcr Elise","ArtistID":1833," ArtistName":"Beethoven","AlbumID":2087629,"AlbumName":"Beethoven and the Sea"}]com/6Jk1","SongID":4925300,"SongName":"Beethoven #4: Adagio","ArtistID":1833,"ArtistName":"Beethoven","AlbumID":842118,"AlbumName":"Beethoven:第 7 和 4 号交响曲"},{"Url":"http://tinysong.com/gGW0","SongID":11896153,"SongName":"F\u00fcr Elise","ArtistID":1833," ArtistName":"Beethoven","AlbumID":2087629,"AlbumName":"Beethoven and the Sea"}]com/gGW0","SongID":11896153,"SongName":"F\u00fcr Elise","ArtistID":1833,"ArtistName":"Beethoven","AlbumID":2087629,"AlbumName":"Beethoven and the海”}]com/gGW0","SongID":11896153,"SongName":"F\u00fcr Elise","ArtistID":1833,"ArtistName":"Beethoven","AlbumID":2087629,"AlbumName":"Beethoven and the海”}]

我怎样才能将这些信息传递给我的 javascript?

4

1 回答 1

4

您得到的“错误”只是一个警告。Tinysong 使用错误的内容类型(“text/html”)传输 JSON 响应。您可以使用curl验证这一点,例如:

curl --head http://tinysong.com/s/Beethoven\?format\=json\&key\=<your key>

可以在此答案中找到脚本无法正常工作的解释以及问题的解决方案(另请阅读评论)。

也许您应该联系 Tinysong,报告有关内容类型的错误并请求 JSONP 支持。

于 2012-08-06T02:45:17.497 回答