Wednesday, 29 April 2009

XMLHttpRequest - GET Method

GET Method:
//object creation.
function getNewHTTPObject()
{
var xmlhttp;
if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
{
try
{
xmlhttp = new XMLHttpRequest();
}
catch (e)
{
xmlhttp = false;
}
}

return xmlhttp;
}

function GetResponse()
{
var xmlHttp= new getNewHTTPObject();
xmlHttp.onreadystatechange = httpCallBack;
/*here httpCallBack is function, this function continues running till get final response.*/

xmlHttp.open('GET','http://www.google.co.in',true);
xmlHttp.Send(null);

}

function httpCallBack()
{
if (xmlHttp.readyState == 4)
{
var xmlDoc = null;
if (xmlHttp.status==200)
{
if (xmlHttp.responseText)
{
var myresp= xmlHttp.responseText;
//myresp geting response from URL.
}
}
else
{
alert('no response or error');
}
}
}

No comments:

Post a Comment