Thursday, December 29, 2011

Ajax Request

function constructXmlHttpRequest(url,data,funName)
{
if (window.XMLHttpRequest)
{
req = new XMLHttpRequest();
req.onreadystatechange = function()
{
constructResponse(req , funName);
};
req.open("POST", url, true);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
req.send(data);
}
else if (window.ActiveXObject)
{
isIE = true;
req = new ActiveXObject("Microsoft.XMLHTTP");
if(req)
{
req.onreadystatechange = function(){
constructResponse(req , funName);
};
req.open("POST", url, true);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
req.send(data);
}
}
}

function constructResponse( req , funName)
{
if (req.readyState == 4)
{
if (req.status == 200)
{
var callBackFunction = funName +"(request)";
var newFunction = new Function("request",callBackFunction);
newFunction(req);
}
else
{
alert("There was a problem in retrieving the data:\n" +req.statusText);
}
}
}

No comments:

Post a Comment

Disqus for yogi's talk

comments powered by Disqus