Sunday, November 13, 2005

How AJAX works

In my recent post where I got a violent flak from one of my readers. I do believe that whatever I post, for that matter, everyone's posts in their own blogs composes freedom. Freedom to express. The anonymous coward commenter had his freedom too. Freedom to read my post, which apparently stepped over his beliefs and freedom to convey his thoughts. Let me now re-explain my side. John Doe, this is for you.
I am not sure whether the post I commented with meant [1] producing and consuming JSON data in java applications or [2] AJAXifing content by meer evaluating JSON through eval. Let me tell you that it is not as simple as you thought. You might be one of the Architects I've been talking about before, who mainly dwell in buzzwords. Yeah, speaking golden sweet-sounding buzzwords will definitely turn PHB heads and they will adore you like a god.

My friend, if you meant point 1, yes, it can be done. It can be done, not just by JSON but with other XML format as well, moreso with non-XML format. My personal preferrence, SOAP. With the inclusion of Rhino in Mustang, it will not mean that now, we can "finally" support AJAX. It doesn't necessarily be AJAX. Java clients and servers has been consuming and producing XML-based data before in the guise of Web Services, B2B, B2C connectivity and the likes. It has been there, even without Rhino.

If you meant point 2, I tell you, this won't be possible, AFAIK. Rhino and other scripting language made available and embedded within Java are not meant to manipulate UI, just like your JavaScript when you tried your DHTMLs. Rhino, Beanshell, etc. are there to extend business logic. These scripting capabilities was made to create extensibility of business logic by mear definition of the script and not statically defined programatically.

But what is AJAX, really. please refer to the link on the image. You can also buy books or refer to AJAX-related sites and wikis. As you can see, AJAX is composed of the following components, but not necessarily these only. Asynchrony may be achieved with something else, e.g. applets. Data format may also be proprietary. But with this, it ain't AJAX anymore.
  • DHTML: XHTML (or HTML) and CSS for presenting information

  • The Document Object Model manipulated through JavaScript to dynamically display and interact with the information presented

  • The XMLHttpRequest object to exchange data asynchronously with the web server. (XML is commonly used, although any format will work, including preformatted HTML, plain text, JSON and even EBML)

The core presentation engine (AJAX Engine) does not have any defined process as well. All I know is that it acts as controller and mediator between the GUI elements (CSS+JavaScript) and the request/response (XML). You really want to learn more, here's what I can suggest you can dwell into: Java, XML, JavaScript, XML, HTML, CSS/P, Servlets/JSPs. Correct me if I am wrong, but in a nice way. Hope you won't be so violent and vindictive next time. Peace!

You can find the original post and post comments here.