Javascript 我在firebug html部分得到了结果。如何将结果加载到主html中

Javascript 我在firebug html部分得到了结果。如何将结果加载到主html中,javascript,spring,Javascript,Spring,我有两个下拉列表。改变第一个下拉列表后,我得到第二个下拉列表值。这两个都是动态下拉列表 更改第一个下拉列表后,我将在firebug html页面中获得查看结果。但我在主html中没有得到相同的结果。如何将相同的结果附加到主html中 这是我的代码: <form:form method="get" commandName="frmSample" action="retrieve" modelAttribute="customer"> <form:select path="Cus

我有两个下拉列表。改变第一个下拉列表后,我得到第二个下拉列表值。这两个都是动态下拉列表

更改第一个下拉列表后,我将在firebug html页面中获得查看结果。但我在主html中没有得到相同的结果。如何将相同的结果附加到主html中

这是我的代码:

<form:form method="get" commandName="frmSample" action="retrieve" modelAttribute="customer">

<form:select path="CustomerId" id="customerDetails">
    <option selected="selected" disabled="disabled">Select Customer</option>
     <form:options items="${map.customerList}"
     itemLabel="customerName" itemValue="customerId" />
</form:select> <br>

选择客户

这是第一个下拉列表值

更改第一个下拉列表后,我将创建ajax调用:

    <script>
    $(document).ready(function() {
        $("#customerDetails").change(function() {
            var value1 = $('#customerDetails :selected').text();
            $.ajax({
                type : 'POST',
                url : 'environments',
                data : {
                    selectedcustomername : value1
                },
                success : function(result) {
                    getEnvNames(result);
               }
            });
        });
    });
</script>

function getEnvNames(result){
    $('#environmentName').empty().append('<option selected="selected" disabled="disabled">Select An Environment</option>');
    var data = JSON.parse(result);
    $.each(data, function(key, value)
    {
        $("#environmentName").append("<option>" + value.environmentName +" - "+ value.environments_purpose + "</option>");

    });

}

$(文档).ready(函数(){
$(“#customerDetails”).change(函数(){
var value1=$('#customerDetails:selected')。text();
$.ajax({
键入:“POST”,
url:'环境',
数据:{
selectedcustomername:value1
},
成功:功能(结果){
getEnvNames(结果);
}
});
});
});
函数getEnvNames(结果){
$('#environmentName').empty().append('Select An Environment');
var data=JSON.parse(结果);
$。每个(数据、函数(键、值)
{
$(“#environmentName”).append(“+value.environmentName+”-“+value.environments_purpose+”);
});
}
这是我的用户界面

<b>Environment:</b>
<form:select path="EnvrironmentId" id="environmentName">                                                                                                                                                    
    <option selected="selected" disabled="disabled">Select An Environment</option>
    <form:options items="${map.environmentnamesList}" itemLabel="environmentName" itemValue="envrironmentId"/>                                                                                                                                                      
</form:select>
</td>
环境:
选择一个环境
这是我的后端:

@RequestMapping(value=“/environments”,method=RequestMethod.POST)
公共模型和查看getenvironments(HttpServletRequest,
HttpServletResponse、@ModelAttribute(“客户”)客户、@RequestParam字符串selectedcustomername)引发异常{
System.out.println(“所选客户名称”+所选客户名称);
ModelAndView model=null;
Map Map=newhashmap();
List customerList=loginDelegate.getCustomerList();
列表环境名称列表=loginDelegate.getEnvironments(selectedcustomername);
Collections.sort(environmentnamesList,newcustomcomparator());

对于(int i=0;i)您需要对ajax请求的结果进行处理。请看下面的q/a:示例。您需要对ajax请求的结果进行处理。请看下面的q/a:示例。