ajax 发送数组和普通参数到后台
js ... var assigneeId = xxx; var assigneeName = $("#yyy").val(); var one=document.getElementsByName('allocation');//获取到复选框的名称 var chose=[]; for(var i=0;i<one.length;i++){ if(one[i].checked==true){ chose.push(one[i].value); } }
$.ajax({ type : "POST", url : ctx+'/sys/order/batchAllocation.json', data:{ assigneeId:assigneeId, assigneeName:assigneeName, ids:chose }, dataType: "json", success : function(response) { if(response.code=="0"){ parent.layer.alert("操作成功"); initTable(); }else{ parent.layer.msg(response.msg, {icon: 2}); } }, error: function (xhr, status, error) { parent.layer.alert("系统异常:"+error); } });
后台java代码:
@RequestMapping(value = "batchAllocation.json", method = RequestMethod.POST) public @ResponseBody Result batchAllocation(@RequestParam(value = "assigneeId", required = false) String assigneeId, @RequestParam(value = "assigneeName",required = false) String assigneeName, @RequestParam(value = "ids[]") String[] ids, HttpServletRequest request, HttpServletResponse response) { logger.info("::::"+assigneeId+" "+assigneeName+" "+ids.length); try { List<String> list= Arrays.asList(ids); return orderService.batchAllocation(assigneeId,assigneeName,list); } catch (Exception e) { logger.error(e.toString()); return new Result(Constants.resultCode.EXCEPTION.getValue(), e.toString()); } }