I'm getting this in my console when I run dataType: "json", success: function (data, textStatus) { var json = $.parseJSON(data); console.log(json); Code (markup): If I look at the network tab in my browser I can see that the browser itself can read the json just fine. If I copy and paste the json into jsonlint it validates. There are no extra characters, no spaces or blank anythings. Any ideas what might be wrong?
Sure can {"membership_id":"11","association_id":"2"} Code (markup): console.log(data) gives me this I figure since it's a simple object I'll just call data.membership_id and be done with it.
Don't know if it's applicable or not but you can use stringify. Something like JSON.parse(JSON.stringify({"membership_id":"11","association_id":"2"})); Not claiming I am familiar with json, just saw a similar example somewhere suggesting doing this if that error occurs.
Do you still get the error if you use the REAL JSON object instead of the jquerytard bs? If not, use the real modern parser directly then use something like JSON3 as a polyfill for legacy IE. ... or just use the polyfill provided at MDN, though it could use a few efficiency tweaks. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON Gah, those multiple VAR, ELSE after RETURN and multiple IF on the same value REALLY makes me want to pimp-slap somebody. Used to be you could trust MDN dev's to have some clue what they are doing. No more it seems...
It works when I try it manually... var jsonData = '{"membership_id":"11","association_id":"2"}'; console.log($.parseJSON(jsonData)); VM324:2 Object {membership_id: "11", association_id: "2"} Code (markup): If your "console.log(data)" function was already saying it's an object before running parseJSON(), then it looks to me like somewhere it was already decoded into an object. The key here I think is this portion of your AJAX request: dataType: "json" Code (markup): You are telling jQuery that it's JSON coming back and it will automatically decode it for you... so in the end you are trying to decode something that's already decoded.