Javascript Cross Domain Ajax

Since I joined Blast Radius I have been introduced to a lot of new and interesting development practices, frameworks and designs that I have always read or heard about, but was never really forced or motivated to imply in my daily progression. One such framework I wrote briefly about is Mojo. Being a framework that has evolved from the Dojo Toolkit my interest peaked this morning when I read a very interesting article on Ajaxian about cross domain transport.

Originally as more of a low level technologist who only picked up ajax and interface development as a smooth view state for communicating with my middle tier controllers I found Javascript to be very much lacking the web services department. Very often the techniques that have been traditionally used consist of one of two strategies for x-domain communication;

1- A remote javascript include is served using:
javascripthover edges to scroll
 
<script type='text/javascript href='http://remotehost/js/api.js?param=1&param2'>
This is usually a server side script that generates the file contents based on the parameters, and then either renders content locally into your DOM, or provides you with a set of methods that will allow you to manipulate the content. This is not a very secure model and does not allow you to interact with raw xml data very robustly, but as long as you trust the source that is rending the content, it is quite efficient.

2- By matter of Proxy.
This method I’ve used very often for direct communication with XML, SOAP, or REST gateways. Generally, I will develop the interface layer to communicate with a server side controller which will then use Curl to invoke the remote data, process and return as an JSON object. I find this method to be very robust, and allows you to create a very extensible gateway for your Javascript cross domain requests.

With that said, the post I read this morning is indicating that a new methodology for cross-domain scripting is emerging in the Dojo framework. By way of the property window.name one can make a remote request and retrieve data without exploiting the ever so wonderful cross domain security model that we are subject to in all our favorite browsers. This concept is very new but interesting. It opens up a whole new world of client side mash-up possibilities that are sure to get the creative juices flowing in the client side development space. Here is an example of it would be implemented:
javascripthover edges to scroll
 
dojox.io.windowName.send(method, args); // simple method
// deferred result
 
var deferred = dojox.io.windowName.send("GET", {url:"http://somesite.com/resource"});
deferred.addCallback(function(result){
  alert("The request returned " + result);
});
Share and Enjoy:
  • Digg
  • del.icio.us
  • Slashdot
  • Technorati
  • Taggly
  • blinkbits
  • Gwar
  • Spurl
  • Netvouz
  • description
  • SphereIt
  • blogmarks
  • blogtercimlap
  • Linkter

RSS feed | Trackback URI

Comments »

No comments yet.

Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.

Trackback responses to this post

28 queries in 0.392 seconds | Code is Poetry | sLajax.com