Tuesday, August 19, 2008

JSONP

It seems not many people know about this. This is the name of the trick that posted in http://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/ since 2005-12-05, three years ago.

JSON with Padding, or simply JSONP is a technique that allows you to transfer JSON data across multiple domains.

The way JSONP works is simple, but requires a little bit of server-side cooperation. Basically, the idea is that you let the client decide on a small chunk of arbitrary text to prepend to the JSON document, and you wrap it in parentheses to create a valid JavaScript document (and possibly a valid function call).

The client decides on the arbitrary prepended text by using a query argument named jsonp with the text to prepend. Simple! With an empty jsonp argument, the result document is simply JSON wrapped in parentheses.

No comments:

Subscribe in a Reader