当前位置: 代码迷 >> Java Web开发 >> 我用ajax做了一个二级级联 用request.getParameter获取不到第二级的数值为啥 ...
  详细解决方案

我用ajax做了一个二级级联 用request.getParameter获取不到第二级的数值为啥 ...

热度:232   发布时间:2012-03-19 16:56:54.0
我用ajax做了一个二级级联 用request.getParameter获取不到第二级的数值为啥
请问要如何获取啊
搜索更多相关主题的帖子: ajax  如何  

----------------解决方案--------------------------------------------------------
这是页面<select name="parentName" class="textarea" id="supertype" onChange="getChildType()">
                                <option value="0">请选择类型</option>
                                <c:forEach items="${list}" var="t" >                     
                                 <option value="${t.parentName }">${t.parentName }</option>        
                                 </c:forEach>              
                                </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                所属小类
                                <select name="childName" class="textarea" id="typeID">              
                                 <option value="0">小类</option>
                                </select>
                                <hr style="color:white">
----------------解决方案--------------------------------------------------------
这是JS
//商品大类小类的级联
        function getChildType(){
        // var  parentName=document.getElementById("parentName").value;
        var parentName=document.search.parentName.options[document.search.parentName.selectedIndex].value;
        sendParentType("getChildTypeServlet?parentName="+parentName);
        
         }
         
         function  sendParentType(url){
             createXMLResponse();
             xmlHttpreq.open("get",url,true);
             xmlHttpreq.onreadystatechange=getResponse;
             xmlHttpreq.send(null);
         }
         function  getResponse (){
             if(xmlHttpreq.readyState==4){
                if(xmlHttpreq.status==200){
                   var text=xmlHttpreq.responseXML;
                   var   childName=text.getElementsByTagName("childName");
                   var   childNameSelect=document.search.childName;
                   childNameSelect.length=childName.length;
                   for(var i=0;i<childName.length;i++){
                      // alert(childName[i].childNodes[1].firstChild.nodeValue);
                       childNameSelect.options[i].text=childName[i].childNodes[0].firstChild.nodeValue;
                       childNameSelect.options[i].value=childName[i].childNodes[1].firstChild.nodeValue;
                   }
                }
             }
         }
----------------解决方案--------------------------------------------------------
以下是引用中国在2012-3-19 16:59:04的发言:

这是JS
//商品大类小类的级联
        function getChildType(){
        // var  parentName=document.getElementById("parentName").value;
        var parentName=document.search.parentName.options[document.search.parentName.selectedIndex].value;
        sendParentType("getChildTypeServlet?parentName="+parentName);
        
         }
         
         function  sendParentType(url){
             createXMLResponse();
             xmlHttpreq.open("get",url,true);
             xmlHttpreq.onreadystatechange=getResponse;
             xmlHttpreq.send(null);
         }
         function  getResponse (){
             if(xmlHttpreq.readyState==4){
                if(xmlHttpreq.status==200){
                   var text=xmlHttpreq.responseXML;
                   var   childName=text.getElementsByTagName("childName");
                   var   childNameSelect=document.search.childName;
                   childNameSelect.length=childName.length;
                   for(var i=0;i<childName.length;i++){
                      // alert(childName.childNodes[1].firstChild.nodeValue);
                       childNameSelect.options.text=childName.childNodes[0].firstChild.nodeValue;
                       childNameSelect.options.value=childName.childNodes[1].firstChild.nodeValue;
                   }
                }
             }
         }

学习java中
----------------解决方案--------------------------------------------------------
直接使用request.getParameter来获取‘childName’的值
----------------解决方案--------------------------------------------------------
  相关解决方案