我得到firebug html section的结果。将结果加载到主html中

时间:2016-01-11 08:35:14

标签: javascript spring

我有2个下拉菜单。第一次下拉的变化我得到第二次下拉值。两者都是动态下拉。

Onchange of first dropdown我得到的结果是带有view的firebug html页面。但是我没有得到相同的结果在主html .how将相同的结果附加到我的主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>

这是第一个下拉值。

onchange of first dropdown我正在创建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>");

    });

}

这是我的用户界面

<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)
    public ModelAndView getenvironments(HttpServletRequest request,
        HttpServletResponse response,@ModelAttribute("customer") Customer customer,@RequestParam String selectedcustomername) throws Exception{
            System.out.println("selected cust name"+selectedcustomername);
            ModelAndView model = null;  
            Map<String, Object> map = new HashMap<String, Object>();
            List<org.mvc.domain.Customer> customerList = loginDelegate.getCustomerList();
            List<org.mvc.domain.Environments> environmentnamesList = loginDelegate.getEnvironments(selectedcustomername);
            Collections.sort(environmentnamesList, new CustomComparator());
            for(int i=0;i<environmentnamesList.size()-1;i++){
                customer.setEnvrironmentId(environmentnamesList.get(0));
                customer.setEnvironmentName(environmentnamesList.get(1));
            }
            map.put("environmentnamesList", environmentnamesList);
            model = new ModelAndView("welcome", "map", map);
            return model;
        }

我在firebug html section中得到结果。将结果加载到主html中。

0 个答案:

没有答案