AJAX: Should You Believe the Hype?
AJAX is the latest craze on the Internet at present. According to a few people, this is a technology that will revolutionize the web in the coming years.
What Does AJAX Stand For?
Asynchronous Javascript and XML or AJAX is a word that is is actually a misnomer. AJAX relies on a Javascript function called XMLHttpRequest, not on XML itself.
XMLHttpRequest
XMLHttpRequest was invented by Microsoft by a team working on a web mail application in 1991. It became prominent after Google used it in three famous projects namely, G mail, Google Suggest and Google Maps. In all the three cases, XMLHttpRequest helped them make a much better user interface than what they expected.
XMLHttpRequest helps you send Javascript to the server to get a new content for writing it back on the page. It provides a streamlined feel to the web applications. It allows users to perform things like submission of forms without the page to go blank and reload. On the Google Maps, you can drag the maps around anywhere without the need to reload the page. This is possible only due to the XMLHttpRequest.
Most browsers other than Internet Explorer support it mainly due to its success with G mail.
Getting Started with AJAX
To get started with AJAX, first of all, create an XMLHttpRequest object in the Javascript code. For Internet Explorer, the following Javascript code is used:
var ajax;
onload = function () {
if (window.ActiveXObject) {
ajax = new ActiveXObject("Microsoft.XMLHTTP");
} else {
ajax = new XMLHttpRequest;
}
}
Here, you have declared AJAX as a global variable, and created a new AJAX object when the page loads, with the use of ActiveX in the Internet Explorer and XMLHttpRequest in the other browsers.
After this, you need to write one function to get the data for a URL and another to handle the data that returns back.
function getText(url) {
ajax.open("GET", url, true);
ajax.send(null);
}
ajax.onreadystatechange = function () {
if (ajax.status == "200") {
// do things with retrieved text (in ajax.responseText)
}
}
With the use of these codes, you can send a request to ajax.php on your server along with the current value of an input box. The ajax.php script checks whether it is already in use, and returns 1 or 0 as output. Depending on the output the page has to be changed, with the use of getElementByID.
Should I Use It?
The answer to this question depends on how useful it is for you. It is good for certain applications where users would be required to submit data again and again, but not useful for smaller ones. AJAX coding takes up a lot of time. So, AJAX should be used only on those projects which are well suited for asynchronous transfer.






















