Pragmatic Studio: Ajax coming to Boston Sept 11-13

The Pragmatic Studio: Ajax is coming to Boston September 11-13. You can check out the site for complete details, but I wanted to mention one thing here: our approach to hands-on exercises.

A big challenge with Ajax training is creating useful hands-on exercises that don't bog attendees down in the details of setting up some random server on their laptops. For the Studio, we have finessed this problem by providing a shared server. Attendees browse to a page, do "View Source", copy a file to their local machine, and edit the HTML file to make calls back to the shared server. This keeps things simple (no server setup) and forces everyone to think about keeping their Ajax code decoupled from server implementation details.

Since calling a remote server from a local HTML file isn't directly legal in Firefox, we provide various versions of the following hack to enabled limited cross-site capability.

  // Modifies Prototype so that Ajax requests ask permission to go cross-site.
  // Useful for pages that are run from the local filesystem.
  CrossSite = {
    wrap: function(original) {
      return function() {
        try {
         netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
        } catch (e) {
          //alert("caught " + e);
        }
        original.apply(this, arguments);
      }
    }
  }
  Ajax.Request.prototype.initialize = CrossSite.wrap(Ajax.Request.prototype.initialize);
  Ajax.Request.prototype.onStateChange = CrossSite.wrap(Ajax.Request.prototype.onStateChange);
  Ajax.Updater.prototype.initialize = CrossSite.wrap(Ajax.Updater.prototype.initialize);

As I have said before, Enterprise software is all about flexibility. It is a testament to the Enterprise-worthiness of JavaScript as a language that I was able to so easily find the hooks needed to make the cross-site hack work. Not to say that this particular hack is the best way to do cross-site Ajax in a production setting, but it is the exact fit for our needs.

Get In Touch