noeticpenguin / ngForce

Force.com && Angular.js integration framework.
noeticpenguin.github.io/ngForce
MIT License
142 stars 61 forks source link

Invalid JSON response using create #29

Closed mogenshoj closed 9 years ago

mogenshoj commented 9 years ago

Hi

I encountered a bug with the response from the create() method. I'm getting an error for invalid syntax: Error: SyntaxError: JSON.parse: expected property name or '}' at line 1 column 2 of the JSON data.

The console showed the response as:

{\"success\":true,\"errors\":[],\"id\":\"a0224000001COAKAA4\"}

Which should work.

But I put a console.log into the code before JSON.parse and saw this response:

{"success":true,"errors":[],"id":"a0224000001COAKAA4"}

I'm not sure why it returns encoded characters for ". It works with every other call I've used so far (first create call I have used so far).

I solved the issue by putting a replace into the JSON.parse argument, like so:

a=JSON.parse(a.replace(/"/ig,'"'))

I can't seem to find a non-minified version (is one publicly available?), so I had to do it in the minified version. I'm sure you can see where it belongs.

noeticpenguin commented 9 years ago

This is an interesting bug. I'm looking into it. I'd rather not apply the work around (a.replace...) until we understand why it's happening more fully. (no offense)

The un minified source is always available at this repo under the jsSrc/* directory.

I believe the unminified file you're looking for is here: https://github.com/noeticpenguin/ngForce/blob/master/jsSrc/subModules/ngForce-visualForceRemoting.js

mogenshoj commented 9 years ago

Ahh, there is it. Thank you :)

No problem not adding the workaround, I just needed to get it working for now.

mattwelch commented 9 years ago

I think I might have figured out the problem here. On create (or update, or bulkUpdate).. pretty much anything except query or queryFromFieldset, the "this.standardOptions" passed in is undefined. For the aforementioned methods, the options are explicitly defined.

The end result of this is that the VF remoting default of escaping the result is in place. This is a "bad thing".

So we need to get those standardOptions defined at instantiation time.

noeticpenguin commented 9 years ago

I believe i've fixed this now.