Hi ...
I Need to work with more AJAX Content, So i want a JS Function with Arguments like URL(the url to Ping), Parameters to Send , ctype(Content Type XML,JSON or TEXT). All i need is when i Call the Function with these Arguments , the Function should return the XML or JSON object back... But the Obj is inaccesible outside the
http.onreadystatechange =function()
{
if(http.readyState == 4 && http.status == 200)
{
obj=http.responseXML;
}
}
i need to access 'obj' here outside the http.onreadystatechange =function(), SO that i can return it to the Called Function ...
Now where am i Missing ... or is there any Alternative ways to do this ...
var url="getxml.php";
var paramstring="abc=20&def=2";
var ctype="XML";
// URL - URL of PHP, paramstring - Parameters to Send , Ctype-ContentType (Strictly XML,JSON,or TEXT)
var xmlobj = GetTHTTPObject(url,paramstring,ctype);
alert(xmlobj); // I need to get the obj returned by the AJAX here ...
function GetTHTTPObject(url,paramstring,ctype)
{
var http = GetXmlHttpRequestObject(); //new XMLHttpRequest();
var params = paramstring;
// var obj;
http.open("POST", url, true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
// if(http.readyState == 4 && http.status == 200)
// alert(http.responseXML);
data=http.onreadystatechange =function() //Call a function when the state changes.
{
if(http.readyState == 4 && http.status == 200)
{
obj=http.responseXML;
}
alert(obj);
return obj;
}
http.send(params);
alert(obj); // How to get the 'obj' accessible here ?
return "obj";
}
Thank You Very Much ...
Regards
Manikanda raj S