Last Updated: February 25, 2016
·
818
· 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.

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside