News for hackers. Stuff that matters.
Re:JSON: The JavaScript subset that isn't by tomstuart on Monday May 16, 2011 @06:12AM (#2552104)
JSONP does force you to use eval, because JSONP means "instead of returning JSON for me to parse with a JSON library, return executable JavaScript for me to point at with the src attribute of a <script> element". The string consisting of the argument to the callback is de facto evaled by the user agent (when the executable JavaScript is executed) in order for it to become a JavaScript value at all.

The user agent evals the JSONP response before anything else happens: the server might return the string 'yourCallback({"JSON":"rocks!"});', which gets evaled to a function invocation whose argument is whatever the string '{"JSON":"rocks!"}' evals to. If that string doesn't successfully eval (as per the OP), your JSONP is broken.

Re:JSON: The JavaScript subset that isn't by rmccue on Monday May 16, 2011 @06:47AM (#2552150)
Perhaps we need a JSONP callback that instead does `yourFunction(JSON.parse('{"JSON":"rocks!"}'))` (though, slightly more sophisticated, I hope).
Re:JSON: The JavaScript subset that isn't by mhansen on Monday May 16, 2011 @09:28AM (#2552442)
That still won't work unless you escape the line endings. And you'll also need to escape single quotes.
Re:JSON: The JavaScript subset that isn't by rimantas on Monday May 16, 2011 @06:35AM (#2552139)
You are mixing eval() with other stuff.
Re:JSON: The JavaScript subset that isn't by threedaymonk on Monday May 16, 2011 @07:16AM (#2552199)
Or, conversely, everyone here is confusing eval() with evaluation in general. JSONP does not call eval() as such, but it does evaluate the server response as JavaScript, because it ends up as:

    <script src="/whatever?callback=foo"></script>
The source of which is something like

    foo({"a":"b"})
Therefore, the hash supplied to foo() must be valid JavaScript.