| Country Rank: | 42 |
|---|---|
| World Rank: | 297 |
| Profile Viewed: | 181 |
| Points: | 181 |
|
19 Jan
2010
|
All you want to know about AJAX
By: Rochak Chauhan
|
Whats Ajax ?
AJAX stands for “Asynchronous JavaScript and XML”, but something tells me you already know that and want to know in layman’s terms.
Alright, AJAX is not a Programming Language nor it is a new Technology as many of us believes it to be. AJAX is nothing but a methodology based on Javascript,XML, xHTML and CSS.
Why AJAX ?
The main feature of AJAX is that it can post or get data from the server without reloading your page. Thats right, it makes a connection to the server using XML and get the required data as plain text or as XML.
Where to use ?
Its has various implementations in forms, validation, Interactive User interfaces etc etc. Thumbs rule is, you can use AJAX anywhere when you need to interact with server to fetch/post a small amount of data. An common example of AJAX implementation can be in the form where you want to check the availability of your desired username.
Any Limitations ?
As they say nothing is perfect, so it applies to AJAX too. It has following limitations:
Final Word !
In the age of Web 2.0, where Web based application is looking in the eye of all existing desktop applications (including Microsoft Word), AJAX has become a necessary evil. It doesn’t matter if the application is a Desktop, Web or Mobile based, the bottom line is if you don’t implement AJAX in it…then its counterpart from Google will take the cake.
How to make an AJAX Call !
1) Create and AJAX Object:
function createAjaxObject() {
//Code for Mozilla
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
}
//Code for IE
else if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
else {
alert("Your browser does not support XMLHTTP.");
}
}
ajaxObj = createAjaxObject();
2) Make a AJAX Call with or without parameters:function makeAjaxCall() {
ajaxObj.onreadystatechange=handleAjaxResponse;
ajaxObj.open("get",url,true);
ajaxObj.send(null);
}
3) Handle the response:function handleAjaxResponse() {
if (ajaxObj.readyState==0){
//ajax is uninitialized
}
else if (ajaxObj.readyState==1){
//ajax is loading
}
else if (ajaxObj.readyState==2){
//ajax is loaded
}
else if (ajaxObj.readyState==3){
//ajax is interactive
}
else if (ajaxObj.readyState==4){
// get as Text
ajaxObj.responseText;
// or
// get as XML
ajaxObj.responseXML;
}
}