I never thought geeks love fancy four letter words, until Ajax happened. Since this term Ajax was coined (more than the happening of Google Maps, GMail etc. ), there has been a renewed interest in XML, Javascript, and DHTML from the perspective of XML binding as native Javascript objects (DOM) and ability to make ad-hoc HTTP requests after a page load (without refreshing the page). However, the technique of refreshing partial content on the page is not new, websites have been doing this with IFRAMEs, etc. to achieve the desired effect. But, it was more of a hack than clean programming.
Before Ajax was born, Microsoft engineers were cranking (1,2) on XMLHttpRequest objects on their MSDN website, and the outlook webclient for exchange. Now (since there is a lot of hype), I remember reading an article in MSDN Magazine which I finally found on the web. Also, to my surprise I found the following piece of Javascript code (thanks to Google Desktop) lurking in my hard-drive of an old desktop. I have no clue which website I copied it from! Anyway, this was my first working Ajax code:
var req;
function processReqChange() {
if (req.readyState == 4) {
if (req.status == 200) {
alert(req.responseXML);
} else {
alert("Request Borked: +
req.statusText);
}
}
}
function loadXMLDoc(url) {
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send(null);
}
}
Above is a very rudimentary code. I don’t even know, if it’s going to work on “all” the browsers.
Doing things the Ajax-way was Javascript’s original goal — but the movement got muffeled by usability pundits and reluctance of companies to piss-off customers who were using the old browsers.
Anyway, there is a good pickup (Ajax has been slashdotted plus there are dedicated blogs) on Ajax. However, there is a lot to be solved with the rest of the web. As Adam Bosworth points out; we still need to solve three fundamental problems viz. Fixing printing of web pages, making the browser listen for external events and having a web application run offline. I think we may be able to get a handle on the last one with Greasemonkey user scripts.
Next part — my Greasemonkey endeavours (I actually wrote some working code mixing Ajax & Greasemonkey with some offline content).