Last Updated: February 25, 2016
·
630
· dakuan

Firefox and $.ajax - careful now…

Don't go forgetting to include this in the options object:

dataType: 'json' 

While Chrome and Safari are clever enough to figure out that a string that looks like this is a json object:

"{ 'id':'123', 'content' : 'blah' }" 

Firefox is not and you will be stuck with that string unless you explicitly tell it that the response is a json object.

Lets say that data is the returned object from the ajax post. Where you have code like this:

var foo = data.id;
var bar = data.content

In Chrome foo will be 123 and bar will be blah. Both variables will be undefined in Firefox. Boohoo.