日期:2014-05-17  浏览次数:20719 次

JS返回值的问题 大侠帮忙!!!
写两个下拉列表。 第一个通过js获得返回值。 添加到第二个下拉列表中。(之前都没有问题)。
问题是 当事件触发第二个 下拉列表时,也想通过js获取返回值。 可是总走到第一个js中的function progessRequest()的里面,为什么啊?????求解释 !!!!


JScript code
<script type="text/javascript">
   //创建连接,判断浏览器
    var http_request=false;
    function createXMLHttpRequest(){
    if(window.XMLHttpRequest){
      XMLHttpReq=new XMLHttpRequest(); //创建对象对应不同的浏览器
    }
    else if(window.ActiveXObject){
      try{
         XMLHttpReq=new ActiveXObject("Msxml2.XMLHTTP");
      }catch(e){
      try{
         XMLHttpReq=new ActiveXObject("Microsoft.XMLHTTP");
      }catch(e){
      }
      }
    }
    }
//onchange事件
function changeProvice(){  
  var lou=document.getElementById("ss").value;    
 sendRequest("ldServlet?lou="+lou);     }
    //发送请求
function sendRequest(url){     createXMLHttpRequest();
    XMLHttpReq.open("GET",url,true);
    XMLHttpReq.onreadystatechange=progessRequest;
    XMLHttpReq.send(null);
    }

function progessRequest(){
    if(XMLHttpReq.readyState==4){
        if(XMLHttpReq.status==200) {
            var xmlDoc1=XMLHttpReq.responseXML; //获取返回的XML文档
            var fangs=xmlDoc1.getElementsByTagName("fang");//获取XML节点
            var obj=document.getElementById("fang");//获取第二级菜单的对象
            if(obj!=null){//如果不为空就置空
                   obj.options.length=0;
                 }
              for(var i=0;i<fangs.length;i++){//用循环给select中加值
                 var xValue = fangs[i].childNodes[0].firstChild.nodeValue;
                 var xText = fangs[i].childNodes[1].firstChild.nodeValue;
                 var option = new Option(xText, xValue);
              try{
                 obj.add(option);
              }catch(e){}
              }
            }else{
                alert( "请求异常"+XMLHttpReq.responseText);
            }
       } 
}
</script>


------解决方案--------------------
JScript code

function changeProvice(){  
  var lou=document.getElementById("ss").value;    
 sendRequest("ldServlet?lou="+lou);     }
    //发送请求
function sendRequest(url){     createXMLHttpRequest();
    XMLHttpReq.open("GET",url,true);
    XMLHttpReq.onreadystatechange=progessRequest;
    XMLHttpReq.send(null);
    }