Ajax
Ajax发请求
1 <script> 2 function isNum() { 3 var num = $("#num").val(); 4 if (num == "" || isNaN(num) || Math.round(num) != num || num < 0 || num > 200){ 5 alert("请填写1-200正整数"); 6 }else { 7 $.ajax({ 8 url:"${ctx}/identification/identityIdentification/save", 9 data:{"num":num}, 10 type:"GET", 11 success:function (data) { 12 $('#myModal').modal('hide'); 13 window.location.href = "${ctx}/identification/identityIdentification"; 14 alert(data); 15 } 16 }) 17 } 18 } 19 </script>
controller
1 /** 2 * 生成身份标识符 3 */ 4 @ResponseBody 5 @RequiresPermissions(value={"identification:identityIdentification:add","identification:identityIdentification:edit"},logical=Logical.OR) 6 @RequestMapping(value = "save",method = RequestMethod.GET) 7 public String save(@RequestParam("num") Integer num){ 8 9 User user = UserUtils.getUser(); 10 Integer count = identityIdentificationService.generateIdentification(num,user); 11 String tips; 12 if (num.equals(count)){ 13 tips = "成功生成" + count + "个身份标识符!"; 14 }else { 15 tips = "成功生成" + count + "个身份标识符,失败" + (num-count) + "个"; 16 } 17 18 return tips; 19 }