2

我正在尝试使用这个 ajax 调用:

var url = ' http://api.official.fm/tracks/D4lw?fields=streaming,cover&api_version=2';

 jQuery.ajax({
    url: url,
    dataType: 'jsonp',
 }).done(function( data ) {
    //console.log(data);
 }).fail(function(jqXHR, textStatus, errorThrown) {
    if(useAlertMessaging) alert('error: ' + jqXHR.responseText);
 });

它适用于 IE10,但在 IE9 及以下版本中出现此错误:

SCRIPT1004: Expected ';' 
D4lw, line 1 character 9

控制台显示:

{"track":{"title":"Love Me As I Have Loved You (prod. Ritz Reynolds)","duration":75,"artist":"Mac Miller","url":"http://api.official.fm/tracks/D4lw?api_version=2","page":"http://official.fm/tracks/D4lw","buy_url":null,"rough_view_count":null,"rough_play_count":null,"rough_download_count":null,"streaming":{"http":"http://api.official.fm/tracks/D4lw/stream?api_version=2","rtmp":"rtmpe://fairtilize-174.fcod.llnwd.net/a2251/r2/mp3:/audio2/s/D4/D4lw_3594640?e=1378301197&h=8a551f822a7fbbc6fe07866626451bc3"},"cover":{"urls":{"large":"//cdn.official.fm/medias/pictures/tu/tuKi_large.jpg","medium":"//cdn.official.fm/medias/pictures/tu/tuKi_medium.jpg","small":"//cdn.official.fm/medias/pictures/tu/tuKi_small.jpg","tiny":"//cdn.official.fm/medias/pictures/tu/tuKi_tiny.jpg"},"id":"tuKi"},"project":{"name":"Mac Miller","url":"http://api.official.fm/projects/f8w6?api_version=2"}}}

光标指向此处的第一个轨道半色之前:

{"track"

对此我能做些什么吗?

(我不控制我使用的网址)

我尝试删除 ajax dataType 但结果是一样的。

4

1 回答 1

1

我在 IE 中的对象中添加额外的逗号时遇到了问题。尝试这个:

jQuery.ajax({
    url: url,
    dataType: 'jsonp' // removed the comma from this line
 }).done(function( data ) {
    //console.log(data);
 }).fail(function(jqXHR, textStatus, errorThrown) {
    if(useAlertMessaging) alert('error: ' + jqXHR.responseText);
 });
于 2013-08-14T18:38:56.837 回答