Note To Self: Parse strings, not JSON objects.

 

 

So the error I was receiving was “invalid token o”.

OK, fine, I have some bad Javascript syntax somewhere… this should be an easy fix, right? Except that all the scripts looked fine. I wasted almost an hour methodically checking all the scripts for an extraneous character, a missing semicolon, etc. I killed domino’s _doClick function, as it has an ‘o’ object, and I’m not using it anyway. Nothing was changing my error.

Until I figured out the problem – the error was coming up on a callback from a jQuery AJAX POST. My normal mechanism on these is to parse the returned data string into a JSON object, then do my work against that object.

However, this particular AJAX POST was already returning it as an object. So when I did my “JSON.parse(data)”, it converted ‘data’ into “[object Object]“. And guess what? That is not valid JSON! So guess what, that ‘o’ is an invalid token!

Yeah, an hour of futzing around only to realize that I didn’t need to parse that object.

About these ads
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: