With JSONP, it looks like:
As a result of added this to the ArcDeveloper REST API, I had to make some “breaking” changes to the project. Firstly, the format must now be specified using the ‘f’ querystring parameter (i.e., f=json or f=jsonp) which maps to a ‘format’ parameter on the service methods. The value of the ‘f’ querystring parameter must match the name of the formatter, as configured in the Windsor configuration. Secondly, in order to pass the callback function name to the JSONP formatter, I chose to basically pass ALL the querystring paramters to every Formatter. That way, if another formatter needs a specific querystring parameter, it will supplied by the service manager for each request. Check the code for more details, if you are interested.
(you will need to do a dojo.require(‘dojo.io.script’) for this to work)
Dojo is kind enough, in this case. to call the function defined in the ‘load’ property of the dojo.io.script.get method above. As far as your code knows, it’s just an AJAX call, but it only works for services that support JSONP.
So, that is JSONP support. I plan on checking in the code after some of the other ArcDeveloper types chime in on my “breaking” changes (mentioned above), which should be tomorrow.
By the way, for anyone developing there own JSONP services, here are a couple of things I ran into:
- Make sure you strip all whitespace out of the JSON before streaming it back to the client. I used a Regex for this.
- The trailing semi-colon ( ; ) on the JSONP call is, apparently, very important.
I’ll edit the post if I hit other issues in the testing.