項目需要實現(xiàn)一個功能 當點下拉框時動態(tài)加載后臺數(shù)據。
這是后臺數(shù)據
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- request.setCharacterEncoding("UTF-8");
- response.setCharacterEncoding("UTF-8");
- Map<String, String> product_names = DataManager.getGroup_names();
- StringBuffer sb = new StringBuffer();
- sb.append("{");
- Set<String> keys = product_names.keySet();
- for(Iterator<String> iter = keys.iterator();iter.hasNext();) {
- String key = iter.next();
- sb.append(product_names.get(key)+":");
- sb.append("['"+key+"'],");
- }
- sb.deleteCharAt(sb.length()-1);
- sb.append("}");
- response.getWriter().write(sb.toString());
- }
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {request.setCharacterEncoding("UTF-8");response.setCharacterEncoding("UTF-8");Map<String, String> product_names = DataManager.getGroup_names();StringBuffer sb = new StringBuffer();sb.append("{");Set<String> keys = product_names.keySet();for(Iterator<String> iter = keys.iterator();iter.hasNext();) {String key = iter.next();sb.append(product_names.get(key)+":");sb.append("['"+key+"'],");}sb.deleteCharAt(sb.length()-1);sb.append("}");response.getWriter().write(sb.toString());}
前臺設值
- $.ajax({
- type:"post",
- url:"InitData",
- data:"",
- success:function(data) {
- var map = eval("("+data+")");
- $.each(map,function(key,values){
- $("<option value="+values+">"+key+"</option>").appendTo("#p_name");
- }
- );
- }
- });