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为什么呢?

解决方案 »

  1.   

    GOOGLE浏览器,IE,都试过 了。
      

  2.   

    alert(jaxFunction('http://localhost/index.php'));///弹出undefined
    中“jaxFunction”有没有写错?
      

  3.   

    alert(ajaxFunction('http://localhost/index.php'))少了个a
      

  4.   

    声明一个全局变量:var Auuu="";
      if(xmlHTTP.readystate==4)
     {
       ......
      Auuu=uuuu;
     }
    函数结尾处:
     xmlHTTP.send(null);
     
     return Auuu==""?"":Auuu;
    }
      

  5.   

    用jquery方便点吧。
    一步一步debug,使用firebug来看看发送和接收的数据
      

  6.   

    对象:
     if(xmlHTTP.readystate==4)
     {
      ......
      this.Auuu=uuuu;
     }alert((new ajaxFunction('http://localhost/index.php')).Auuu);