tags:

views:

410

answers:

3

What is JSONP, why is it needed, and what are some real world examples of it's usage.

+3  A: 

http://remysharp.com/2007/10/08/what-is-jsonp/

andersonbd1
Thanks, that's a pretty good article. I did realize that I was also looking for some good background on why it is necessary, which the article doesn't really cover, so I will rephrase my question to include that.
Mark Kanof
from the article "in doing so, you can have cross domain JSON requests."it's a way to get around xss limits
andersonbd1
+3  A: 

JSONP stands for JSON with padding, and it provides a way for the client to specify some code that should be added to the start of the JSON response. This allows the JSONP response to be directly executed in the browser. An example of a JSONP response might be:

processResults({value1: "Hello", value2: "World"})

I think the major place that JSONP would be useful is in making requests across domains using the <script> tag. I think the major disadvantage is that as the JSONP is directly executed you would have to trust that the remote site wouldn't send back anything malicious. However I have to admit that I haven't used the technique in practice.

Edit: Remote JSON - JSONP provides more information on why you would want to use the technique from the guy who appears to have invented it.

blackNBUK
+3  A: 

Quoting from this blog:

The purpose of JSONP is to overcome the boundaries of the infamous same-domain-policy which restricts XHR requests to the same domain meaning that you cannot make Ajax requests to other domains. There’s no need to worry about that with JSONP because it doesn’t even require Ajax to work; all it’s doing is using script tags and callbacks…

Kevin