Cross domain Ajax requests in Dojo…. and there was much rejoicing
Posted by Shane O'Sullivan on August 1, 2006
This is going to be huge! Dojo now supports cross domain Ajax requests, something that has been out of the reach of most Web 2.0 programmers until now. It’s implemented using Iframes, which has both pros and cons (get more info here) but against the couple of issues people might have with it are the two facts:
- It works! It might use more memory, or it may be slower than normal, but dammit, it works! If you want to keep on using server side proxies or Flash, that’s fine, but here is a standalone, client-side solution that works.
- It’s ridiculously simple to use. As with all other remote requests in Dojo, the mighty dojo.io.bind function is used, this time with a single new parameter. As the documentations states, you do:
dojo.require(“dojo.io.*”);
dojo.require(“dojo.io.XhrIframeProxy”);
dojo.io.bind({
iframeProxyUrl: “http://some.domain.com/path/to/xip_server.html”,
url: “http:/some.domain.com/path/to/api”,
load: function(type, data, evt, kwArgs){
/* do stuff with the result here */
}
});
and it all just works. The emboldened parts are the only client-side changes that have to made to existing code. There needs to be server side support too of course, but that is the case with all Ajax sites, so it’s hardly something to criticise.
Final verdict is that this is one of the most important additions to Dojo (after the namespace support of course *ahem*) in quite some time.
Now, as for the security/morality of doing remote Ajax calls….. after all, browsers block it for a reason. Very nasty things can be done if you can access any remote content you like from a Javascript enabled client. However, it seems that this code can only go against remote endpoints that support this Dojo feature, so there should hopefully be no problem there either. Seems like this one’s a keeper folks.

Kieran Lynam's Blog said
Wow: Microsoft Photosynth
A friend of mine just sent me this article about a piece of software coming out of Microsoft…