manisvembu

Hi scrappedcola,
I am already doing what you said...
Here's the Code ...
[CODE]function AJAXReuqest(url,paramstring,ctype)
{
httpReq = GetXmlHttpRequestObject(); //new XMLHttpRequest();
var params = paramstring;
contentType = ctype;
httpReq.onreadystatechange = AjaxResult;
httpReq.open("POST", url, true);
httpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
httpReq.send(params);

}

function AjaxResult() //Call a function when the state changes.
{
if(httpReq.readyState == 4)
{
if(httpReq.status == 200)
{
if(contentType=="XML")
{
obj=httpReq.responseXML;
}
if (contentType=="JSON" || contentType=="TEXT")
{
obj=httpReq.responseText;
}
var click=1;
mani(obj,click);
}
}
}[/CODE]

[CODE]var clickcount=0;
function mani(obj,click)
{
var url="getxml.php";
var paramstring="abc=200&def=2";
var ctype="XML";
clickcount +=1;
// URL - URL of PHP, paramstring - Parameters to Send , Ctype-ContentType (Strictly XML,JSON,or TEXT)
if(click==0)
{
// alert("Click=0");
AJAXReuqest(url,paramstring,ctype);
}
if(click==1)
{
alert("Click=1"+obj);
typeobj=""+obj+"";
if(typeobj=="[object XMLDocument]")
{
// alert("XML");
colarray=["No","SGClicks"];
DrawTable(obj,colarray);
return;
}
}
}
function thk()
{
click=0;
obj=new Object();
mani(obj,click);
}[/CODE]

I thought there may be a way to access the AJAX Response out of httponreadystatechange function , which i may not know ...
Thanks for the reply...

manisvembu Newbie Poster

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 ...

[CODE]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 ...
[/CODE]

[CODE]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";
}[/CODE]

Thank You Very Much ...
Regards
Manikanda raj S