首页 > 编程语言 > 详细

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

时间:2015-08-19 11:07:13      阅读:362      评论:0      收藏:0      [点我收藏+]

  

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();
    }

 

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

原文:http://www.cnblogs.com/QinH/p/4741387.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!