function ajaxFunction(url)//////////ajax
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{ // Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
for( var i = 5; i; i-- )
{
try{
if( i == 2 ){
xmlhttp_request = new ActiveXObject( "Microsoft.XMLHTTP" ); }
else{
xmlhttp_request = new ActiveXObject( "Msxml2.XMLHTTP." + i + ".0" );
}
break;
}catch( e)
{
}
}
xmlhttp_request.setRequestHeader("Content-Type","text/xml");
xmlhttp_request.setRequestHeader("Charset","gb2312");
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
var uuuu= xmlHttp.responseText.toString();
alert(uuuu);///弹出内容,正确。
return uuuu;
}
}
xmlHttp.open("POST",url,true);
xmlHttp.send(null);
}alert(jaxFunction('http://localhost/index.php'));///弹出undefined为什么呢?
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{ // Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
for( var i = 5; i; i-- )
{
try{
if( i == 2 ){
xmlhttp_request = new ActiveXObject( "Microsoft.XMLHTTP" ); }
else{
xmlhttp_request = new ActiveXObject( "Msxml2.XMLHTTP." + i + ".0" );
}
break;
}catch( e)
{
}
}
xmlhttp_request.setRequestHeader("Content-Type","text/xml");
xmlhttp_request.setRequestHeader("Charset","gb2312");
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
var uuuu= xmlHttp.responseText.toString();
alert(uuuu);///弹出内容,正确。
return uuuu;
}
}
xmlHttp.open("POST",url,true);
xmlHttp.send(null);
}alert(jaxFunction('http://localhost/index.php'));///弹出undefined为什么呢?
中“jaxFunction”有没有写错?
if(xmlHTTP.readystate==4)
{
......
Auuu=uuuu;
}
函数结尾处:
xmlHTTP.send(null);
return Auuu==""?"":Auuu;
}
一步一步debug,使用firebug来看看发送和接收的数据
if(xmlHTTP.readystate==4)
{
......
this.Auuu=uuuu;
}alert((new ajaxFunction('http://localhost/index.php')).Auuu);