Brian Teeter
Brian Teeter

Reputation: 876

Firefox/Firebug JSON.parse errors but only locally

I am running into a very peculiar error. We have an application that makes a lot of JSON calls to do things. The app works perfectly fine on all environments, local, dev, preprod, and prod with Chrome, IE and Safari. Firefox works fine on all environments except local. If you run the code locally you get the following errors, hundreds of them, on nearly every JSON.parse call:

JSON.parse: unexpected character

the JSON response is, for example:

[{"id":"724111437775422","order":0,"link":"","name":"Thumb Logo Transparent Back","active":true,"altText":"","url":"http://localhost/storm/mediamanager/retrieveMedia?id=724111437775422"}]

The JS code itself is:

$.ajax({
type: 'GET',
url: requestUrl,
success: function(msg){
var parsed = JSON.parse(msg);
callback(key, mediaType, targetSelector, parsed);
},
error : function(jqXHR, textStatus, errorThrown){
if(Media.debug)
//alert('getActiveMediaList: ' + JSON.stringify(jqXHR) + " | " + textStatus + " | " + errorThrown);
var ignoreThis = 1;
}
}); 

I've tried setting MIME types from the server side, I've tried trimming the JSON, I've tried a lot of things and no matter what Firefox seems lost parsing this JSON data.

Any ideas?

Upvotes: 0

Views: 745

Answers (1)

charlietfl
charlietfl

Reputation: 171669

You don't need to use JSON.parse within $.ajax success, jQuery will parse it already internally. You should also set dataType option in $.ajax to dataType:'json'

Upvotes: 1

Related Questions