Toniq
Toniq

Reputation: 5006

Jquery ajax error internet explorer

I ma trying to use this ajax call:

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);
 });

It works in IE10, but in IE9 and below I get this error:

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

console shows:

{"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"}}}

cursor is pointing right before the first track semicolor here:

{"track"

Is there anything I can do about this?

(I dont control the url I use)

I tried remove ajax dataType but the result is the same.

Upvotes: 2

Views: 3707

Answers (1)

Matthew R.
Matthew R.

Reputation: 4350

I have had issues with adding an extra comma in objects in IE. Try this:

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);
 });

Upvotes: 1

Related Questions