注册 登录
编程论坛 J2EE论坛

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

中国 发布于 2012-03-19 16:56, 723 次点击
请问要如何获取啊
4 回复
#2
中国2012-03-19 16:58
这是页面<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">
#3
中国2012-03-19 16:59
这是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;
                   }
                }
             }
         }
#4
C_戴忠意2012-03-20 15:48
以下是引用中国在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中
#5
柠檬可乐2012-03-22 16:25
直接使用request.getParameter来获取‘childName’的值
1