Interested in a long term business with us  contact us »
 

AJAX

Ajax

The term Ajax has come to represent a broad group of web technologies that can be used to implement a web application that communicates with a server in the background, without interfering with the current state of the page. In the article that coined the term Ajax, Jesse James Garrett explained that it refers specifically to these technologies:

XHTML and CSS for presentation
the Document Object Model for dynamic display of and interaction with data
XML and XSLT for the interchange and manipulation of data, respectively
the XMLHttp Request object for asynchronous communication
JavaScript to bring these technologies together

Since then, however, there have been a number of developments in the technologies used in an Ajax application, and the definition of the term Ajax. In particular, it has been noted that:
JavaScript is not the only client-side scripting language that can be used for implementing an Ajax application. Other languages such as VBScript are also capable of the required functionality.
XML is not required for data interchange and therefore XSLT is not required for the manipulation of data. JavaScript Object Notation (JSON) is often used as an alternative format for data interchange, although other formats such as preformatted HTML or plain text can also be used.

How to use

I won't pretend you don't need at least an intermediate JavaScript knowledge to get your head round it all. The trouble is that it's not easy to separate the Ajax "logic" from your own code. There's a reason for this and it's something that caught me out for a while.
The way Ajax works is confusing at first. Your code calls a function which triggers the request for some XML. Obviously this is not an instantaneous transaction and so the code has to wait until the response has been received. Once the XML has been returned it is passed back to the same calling function for processing. Hence, this function runs twice - once to fetch the results and once to process them. What you can't do is something like the function below, where checkModifedDate() is the function which both requests the XML and processes it:

function doSubmit() {
if ( checkModifiedDate( sUNID ) ) {
document.forms0.submit();
}

There's a simple reason for this. The first time the checkModifiedDate() function is called it's simply calling for the XML. There's no logic involved at this point. So the if() statement always processes and the form submits. To get round this we have to move the form submit() call inside of the checkModifiedDate() function to the point where the XML is processed! This makes it harder to hide the more complicated code away in a library somewhere.

« Back