• 二级联动(jquery-ajax-json-springmvc)


      

    html代码

    <select id="firstDepartment" onchange="onChange()">
      <option value="0">1</option>
      <option value="1">1</option>
      <option value="2">2</option> </select> <select id="secondDepartment"/>

    js代码

    //firstLevelName  一级下拉框
    //secondLevelName 二级下拉框

    function onChange(){ var firstLevelName
    = $('#firstDepartment').val(); $.ajax({ url: 'getSecondLevelNames', type: 'get', contentType: "application/json; charset=utf-8", data:{firstLevelName: firstLevelName}, dataType: 'json', success: function(data){ var names = data.secondLevelNames; $('#secondDepartment').empty(); for(var i in names){ $("<option value = '" + decodeURI(names[i]) + "' >" + decodeURI(names[i]) + "</option>").appendTo($('#secondDepartment')); } } } ); }

    后台代码

        @RequestMapping(value = "/getSecondLevelNames", method = RequestMethod.GET)
        public @ResponseBody String getSecondLevelNames(@RequestParam(value = "firstLevelName") String firstLevelName){
    
            List<String> secondLevelName = LevelUtil.getSecondLevelNames(firstLevelName);
            JSONObject json = new JSONObject();
            json.put("secondLevelNames", secondLevelName);
    
            return json.toString();
        }
  • 相关阅读:
    行转列
    multipath 安装配置
    网卡绑定
    numa对MySQL多实例性能影响
    Fatal NI connect error 12170
    REVOKE DBA权限要小心
    Oracle 数据库整理表碎片
    listagg 函数
    10046 事件补充
    tkprof 解释
  • 原文地址:https://www.cnblogs.com/QinH/p/4741387.html
Copyright © 2020-2023  润新知