PDA

View Full Version : How can i return my value as a variable with ajax?



web.designer.iq
05-19-2009, 07:33 AM
Hi
I want to return my ajax value as a variable with "return" keyword. But i don't know why i can't do it!!! It return an "undefined"!! It can't return my page content!!
I use this code:

function ajaxPostRef(url, params )
{
if( navigator.appName == "Microsoft Internet Explorer")
{
var http = new ActiveXObject("Msxml2.XMLHTTP");
}
else
{
var http = new XMLHttpRequest();
}

http.open("POST", url, true);

http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params .length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {//Handler function for call back on state change.
if (http.readyState == 1)
{
//
}

if( http.readyState == 4 && http.status==200 )
{
return http.responseText;
}
}

http.send(params);

}