我是写了两个js函数  用的ajax
我的目的就是要在procTextLink()这个函数中也取到  name
但是name只有在getTextLink()这个函数中才取得到  name是我从界面上调用getTextLink()时传进来的。
 请教高手  我怎么才能取到呢?
var xmlhttpObjTextLink;
         function getTextLink(name) {
         debugger;
            xmlhttpObjTextLink = getXMLHTTPRequest();
            xmlhttpObjTextLink.open("POST", "WebService.asmx/TextLink", true);
            xmlhttpObjTextLink.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            xmlhttpObjTextLink.onreadystatechange = procTextLink;              xmlhttpObjTextLink.send("name=" + name+"");
            return true;
        }
        
        function procTextLink() {
            if (xmlhttpObjTextLink.readyState == 4) {
            if (xmlhttpObjTextLink.status == 200) {
               var doc = xmlhttpObjTextLink.responseXML;
                var cs = doc.documentElement.getElementsByTagName("Table"); 
                var linkHTML='<div style="display:none; text-align: center" id="'+name+'" class="helplay">';
                            
                //要拼接的HTML字符串    var
             linkHTML = '<table width="785" border="1" cellpadding="0" bordercolor="#CC6600" cellspacing="0" align="center">';
                linkHTML += '<tr><td width="116" height="15" >机型代码</td> <td width="122">飞机类型</td><td width="112" >座位数</td><td width="174" >飞机型号</td> <td width="252" >英文</td> </tr>';
                linkHTML += '<tr>';
                for (var i = 0; i < cs.length; i++) {
                    var a = cs[i];
                    linkHTML += '<td><div style="width:auto; text-align:center">';
                      linkHTML += a.childNodes[0].childNodes[0].nodeValue;
                      linkHTML+='</td><td><div style="width:auto; text-align:center">';
                    linkHTML += a.childNodes[1].childNodes[0].nodeValue;
                      linkHTML+='</td><td><div style="width:auto; text-align:center">';
                   linkHTML += a.childNodes[2].childNodes[0].nodeValue;
                   linkHTML+='</td><td><div style="width:auto; text-align:center">';
                   linkHTML += a.childNodes[3].childNodes[0].nodeValue;
                     linkHTML+='</td><td><div style="width:auto; text-align:center">';
                   linkHTML += a.childNodes[4].childNodes[0].nodeValue;
                  
                    linkHTML += '</td>';
                }
                linkHTML += '</tr>';
                linkHTML += "</table> ";
                linkHTML+="</div>";
                showInfo.showLayer(event,name)
                debugger;
                if (document.getElementById("right").innerHTML == "")
                    document.getElementById("right").innerHTML = linkHTML;
                else
                    document.getElementById("right").innerHTML += linkHTML;
            }
            }
        }
    </script>

解决方案 »

  1.   

    定义成全局的var name;fucntion aa()
    {
       alert(name);
    }function bb()
    {
       name='name';
    }
      

  2.   

    xmlhttpObjTextLink.onreadystatechange = function(){
    //procTextLink()函数的代码剪切到这里
    }
      

  3.   

    同一个onmouseover调用两个脚本方法 想让它按顺序执行
    一个是 ajax方法 取出数据拼成一个div  与表格嵌套
     然后又调用另一个方法 js方法
    这个js方法要用到 ajax取出的数据拼成的  div  ,可是就是一个鼠标onmouseover事件 
    我是这样调用的  getTextLink()是ajax方法     showInfo.showLayer()是js方法
     onmouseover="getTextLink('<%#Eval("id") %>'),showInfo.showLayer(event,'<%#Eval("id") %>')"他执行时  getTextLink()没执行完就去执行 showInfo.showLayer()
    所以就报错说 缺少对象了  也就是那个div有啥方法可以让它 getTextLink()先执行完  再去执行showInfo.showLayer()吗?
      

  4.   

    同一个onmouseover调用两个脚本方法 想让它按顺序执行
    一个是 ajax方法 取出数据拼成一个div 与表格嵌套 然后又调用另一个方法 js方法
    这个js方法要用到 ajax取出的数据拼成的 div ,可是就是一个鼠标onmouseover事件 
    getTextLink()是ajax方法 
    showInfo.showLayer()是js方法
    我是这样调用的 :
    onmouseover="getTextLink('<%#Eval("id") %>'),showInfo.showLayer(event,'<%#Eval("id") %>')"他执行时 getTextLink()没执行完就去执行 showInfo.showLayer()
    所以就报错说 缺少对象了 也就是那个div有啥方法可以让它 getTextLink()先执行完 再去执行showInfo.showLayer()吗?