直接导入jquery包
<script type="text/javascript" src="jquery-1.8.0.min.js"></script>
前端代码
fcuntion commit(id){
$.ajax({
type: 'post',
async: true,
url: "service.do?service",
data: JSON.stringify({"id":id}),
dataType: 'json',
contentType : "application/json",
success:function(data){
if(data.success){
console.log(data)
}else{
console.log(data)
}
},
error:function(jqXHR){
aler("发生错误:"+ jqXHR.status);
}
});
}
后端代码
@RequestMapping(params = "service")
@ResponseBody
public JSONObject service(HttpServletRequest request, @RequestBody JSONObject data) throws Exception {
String message = null;
JSONObject j=new JSONObject();
String id=data.getString("id");
message = "获取ID成功";
try{
j.put("id",id);
j.put("success",true);
}catch(Exception e){
e.printStackTrace();
message = "获取ID失败";
throw new BusinessException(e.getMessage());
}
j.put("msg",message);
return j;
}
总结
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200923222003105.png#pic_center)