Saturday, August 12, 2006

AJAX basics

The wirdz site used AJAX to provide much of the functionality and ease of use. This has been taken furthest so far with the Wordnet 2.1 based English Dictionary plus and Roget's Thesaurus.

When this blog started, some technical material of AJAX was promised. So here's a basic intro to start with.

The key to AJAX is that it allows interaction and updated content to be obtained from the back end web/application server without needing a full page refresh. This is what allows the update as you type feature of the itanda dictionary engine to work. It is also the approach behind rich feature applications such as google's online spreadsheet which has been launched in beta status.

The orchestration of the AJAX interaction takes place between javascript running in the browser and whatever active page technology is being used at the back end - this can be PHP, ASP, Java servlets/server pages, Ruby on Rails ... your choice.


The first step on the client/browser side is to create a HTTP request object. Here's the code used on itanda. You'll find variants of this elsewhere on the web. This works with most browsers.
var objReq;

function initialize() {
  try {
    objReq = new ActiveXObject("Msxml2.XMLHTTP");
  }
  catch(e) {
    try {
      objReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch(e2) {
      objReq = null;
    }
  }
  if (!objReq && typeof XMLHttpRequest!="undefined") {
    objReq = new XMLHttpRequest();
  }
}


Interaction takes place in two stages (a) sending a request and (b) processing the return. Here's some sample script:

/* Send request */
if (objReq != null) {
  objReq.onreadystatechange = processReturn;
  strRequest = "http://www.itanda.com/demo/ajaxDemo1.php"
  objReq.open("GET", strRequest, true);
  objReq.send(null);
}

/* Process return */
function processReturn() {
  if (objReq.readyState == 4) {
    if (objReq.status == 200) {
      if (objReq.responseText == "") {
        response.write(objReq.responseText);
      }
    }
  }
}  

In practice the original request will include some parameters and the return processing will be just a tad more sophisticated.

To complete the picture, here's the classic example played out at the back end in PHP:
<?
echo "Greetings earthlings - we now call the shots" .
     " - forget bringing your leader" .
     " - he's got nothing worth saying!";
?>


And that's it folks ...


Wörterbuch Deutsch-Englisch (or German-English Dictionary)

The wirdz site now includes a German-English Dictionary with an English-German one to follow once a few gremlins in the source data are sorted out (well several hundred actually but mostly amenable to an automated fix).

Because of the growing number of dictionaries and related content, the left hand dictionary links menu is becoming unwieldy (schwerfällig or unhandlich according to the dictionary above).


Going forward, wirdz will include separate language variants, probably with a option selector at the top right of the screen. In the meantime, the German-English dictionary is not directly linked - so the reference above is its one chance to get spidered.

Friday, August 11, 2006

Wordnet and a dictionary search add-on for web pages

The wirdz dictionary site now includes the contents of WordNet 2.1 from 2005 Princeton University. In addition to standard dictionary contents, WordNet also includes extensive cross links between words/word groups.

On wirdz, the AJAX dictionary interface has been enhanced to allow backward and forward navigation of the links.

wirdz now also offers a dictionary search drop in for web sites similar to the ones from search engines. It looks like/works like this:







wirdz dictionary





Adding a link to a site simply involves adding the following html code:
<script src="http://www.wirdz.com/searchLink.php"
           type="text/javascript">
</script>
One good thing about itanda pages gerenated through the link is that because the keyword is passed as a query string (GET) parameter, this appears to be spotted by adsense and results in the advert links taking it into account. More varied/interesting links result since the wirdz dictionary pages, excluding the AJAX generated material, are by intention uncluttered and consequently are lacking in content which adsense can work on - the result is a fixation on dictionary or language related links - if google applied adsense to the main google page, much the same outcome would result.