var xmlHttp;
var GetResult;
    function createXMLHttpRequest()
    {
        if(window.ActiveXObject)
        {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else if(window.XMLHttpRequest)
        {
            xmlHttp = new XMLHttpRequest();
        }
    }    function showResult()
    {
        if(xmlHttp.readyState==4)
        {
            if(xmlHttp.status==200)
            {
                GetResult=xmlHttp.responseText;    //假设这边返回123
                return GetResult;
            }
        }
    }    function XmlHttpSend(inurl) 
    {        
        var url=inurl;
        createXMLHttpRequest();
        xmlHttp.onreadystatechange = showResult;
        xmlHttp.open("GET",url,true);
        xmlHttp.send(null);
    }
    function GetReturn(URL)
    {
      createXMLHttpRequest();
      return GetResult;
    }

解决方案 »

  1.   

    var xmlHttp;
        function createXMLHttpRequest()
        {
            if(window.ActiveXObject)
            {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            else if(window.XMLHttpRequest)
            {
                xmlHttp = new XMLHttpRequest();
            }
        }
        function GetReturn(URL) 
        {        
            var url=URL;
            createXMLHttpRequest();
            xmlHttp.onreadystatechange =function(){
              if(xmlHttp.readyState==4){
                   if(xmlHttp.status==200){
                     var GetResult=xmlHttp.responseText;    //假设这边返回123
                    return GetResult;
                   }
                }
             }
            xmlHttp.open("GET",url,true);
            xmlHttp.send(null);
        }
      

  2.   

    createXMLHttpRequest和function XmlHttpSend可以合并
    showResult()回发处理函数一般是单独的,毕竟请求到了才执行,
    不是立马就执行的,所以放一起不合适。
    var xmlHttp;
        function createXMLHttpRequest()
        {
            if(window.ActiveXObject)
            {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            else if(window.XMLHttpRequest)
            {
                xmlHttp = new XMLHttpRequest();
            }
            var url="aaa.ashx";
            createXMLHttpRequest();
            xmlHttp.onreadystatechange = showResult;
            xmlHttp.open("GET",url,true);
            xmlHttp.send(null);
        }    function showResult()
        {
            if(xmlHttp.readyState==4)
            {
                if(xmlHttp.status==200)
                {
                    var GetResult=xmlHttp.responseText;    //假设这边返回123
                    return GetResult;
                }
            }
        }
      

  3.   

     function GetReturn(URL) {    
            var xmlHttp; 
            if(window.ActiveXObject){ 
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } 
            else if(window.XMLHttpRequest){ 
                xmlHttp = new XMLHttpRequest(); }         var url=URL; 
            createXMLHttpRequest(); 
            xmlHttp.onreadystatechange =function(){ 
              if(xmlHttp.readyState==4){ 
                  if(xmlHttp.status==200){ 
                    var GetResult=xmlHttp.responseText;    //假设这边返回123 
                    return GetResult; 
                  } 
                } 
            } 
            xmlHttp.open("GET",url,true); 
            xmlHttp.send(null); 
        }