Cross domain Ajax requests in Dojo…. and there was much rejoicing

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.

6 thoughts on “Cross domain Ajax requests in Dojo…. and there was much rejoicing

  1. I just couldn’t depart your site prior to suggesting that I really loved the standard info an individual provide
    for your visitors? Is going to be again continuously in order to check out new posts

  2. Woah! I’m really digging the template/theme of this website.

    It’s simple, yet effective. A lot of times it’s challenging to get
    that “perfect balance” between superb usability and visual appearance.
    I must say that you’ve done a fantastic job with this.
    In addition, the blog loads extremely fast for me
    on Internet explorer. Superb Blog!

  3. Hey very cool blog!! Man .. Beautiful .. Wonderful ..
    I will bookmark your web site and take the feeds also?
    I’m happy to find so many helpful info right here within the post,
    we want work out more techniques in this regard, thank you for sharing.
    . . . . .

Leave a reply to auto insurance Cancel reply