ajax 请求后台并遍历

xiaoxiao2021-02-28  118

$.ajax({     url:"${ctx}/place/basePlace/getDict",      type:"post",      dataType:"json",      data:{       "type" : "place_type",       "ParentId" : value      },     success:function(data){      debugger       $("#place_type").empty();          // 实际的应用中,这里的option一般都是用循环生成多个了           var options = "";           $.each(data.dicts, function (index, item){            options += "<option value ='"+item.value+"'>"+item.label+"</option>"          });           $("#place_type").append(options);     },     error:function(data,status){      alert("请求出现错误,请联系管理员!");      $("#code").val('');     }    })

后台

@ResponseBody  @RequestMapping(value = "getDict")  public Map<String,Object> getDict(Dict dict,HttpServletRequest request, HttpServletResponse response,Model model) {   Map<String,Object> result = new HashMap<String, Object>();   List<Dict> dicts = new ArrayList<>();   if(StringUtils.isNotBlank(dict.getParentId()) && StringUtils.isNotBlank(dict.getType())){    dicts = basePlaceService.findDicts(dict);   }   if(dicts != null){    result.put("dicts", dicts);   }   return result;  }

转载请注明原文地址: https://www.6miu.com/read-30845.html

最新回复(0)