Edentity Web Systems
You solve creative. We crack code.
/Header/WhoWeAre.jpg
 

09/08/2009 How JSONP works
Posted by Joel Varty

There are a plethora of explanations for JSONP (JSON with Padding, I think it stands for) out there – just search for “how JSONP works” and you’ll get a ton of descriptions.  JSONP is provided as an alternative to normal JSON by jQuery on the client side to enable the invocation of services outside of the current domain.

Some of them are incorrect in explaining that this technology uses a server-server proxy to call out to another server outside of the current domain.

This is NOT a server-server technology, but rather more like the way a lot of Ad servers work by injecting javascript into the page using document.write() with a script tag.

The url for the script tag has a querystring parameter which become that javascript function that wraps up the JSON return value of the web method.  Essentially, a document.write() call creates a script tag on the page which goes to whatever server you want to, and then returns a javascript function object which will get invoked when the script’s response is evaluated by the browser.  This means that the server code has to be tweaked to wrap the JSON return in that function call.

One thing you will not get from JSONP is notification of network errors or anything that responds nicely to badly formed responses, so you have to accept that as a tradeoff with the ability to invoke services on other domains.

This is a very high level explanation of JSON, but I hope it gets you started in right direction.

More later - joel

« Back to Blog Main Page |

0 Comment(s)

Leave Comment

Name:
Comment:  
 
Security Check: 
 
 
Edentity Web Systems Inc.
Suite 201
40 Spadina Ave.
Toronto ON
M5V 2H8
Tel:
416.591.2500
Fax:
416.352.5270
Home | Who We Are | What We Do | Clients & Brands | Careers | Contact

Copyright © 2010 Edentity Web Systems Inc. Privacy Policy