ajax的POST方法使用
前端js代码:
var msg= $("#test").val(); $.ajax({ async : false, type: "post", url: "/push/", contentType:'application/json;charset=UTF-8', data: msg, error : function(request) { }, success : function(data) { alert(data.code); } });
controller层代码
@RequestMapping(value = "push", method = RequestMethod.POST) @ResponseBody public JSONObject pushMessage(@RequestBody String msg){ JSONObject jsonObject = new JSONObject(); jsonObject.put("code",0); return jsonObject; }