ajax(asynchronous java script and xml) is an asynchronous version of java script. that means, on synchronous request,the full page is reloaded and user has to wait until it loaded. but at asynchronous request, page remains as before when requested and only the portion, that requires changes, is changed after response recievied . Thress basic steps are enough to handle asynchronous request:
* create request object
* send request
* receive response
here is the function that creats & return request object:
function HTTPObject()
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
return xmlHttp;
}
Here is how to send the request:
var xmlHttp = HTTPObject();
var req = "a relative/absolute url";
xmlHttp.open("GET",req,true);
xmlHttp.send(null);
Here is the code snippet to receive the response:
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
alert(xmlHttp.responseText);
}
}
Just using this basic concept many more complex ajax operations can be achieved. Just try out.
Subscribe to:
Post Comments (Atom)










0 comments:
Post a Comment