Ajax以POST方式向后台传数据,却出现HTTP Status 405 - Request method 'GET' not supported错误
程序代码:
function insistUser2(){ $.ajax({ type:'POST', url:'http://localhost:8080/OnlineLibraryClient2/insertUser', async:true, contentType:'application/json;charset=utf-8', <!--将输入数据传到Controller--> data:JSON.stringify({ "id" : $("#insert_id").val(), "userName" : $("#insert_userName").val(), "password" : $("#insert_password").val(), "level" : $("#insert_level").val(), "institute" : $("#insert_institute").val(), "major" : $("#insert_major").val(), "tel" : $("#insert_tel").val() }), dataType:'json', success : function(data) { parent.document.location.reload();//刷新页面 }, error : function(msg) { alert(JSON.stringify(msg.message)); } }); }
程序代码:
@RequestMapping(path = "/insertUser", method = RequestMethod.POST) public @ResponseBody ResultVO<User> insertUser(@RequestBody HashMap<String, String>param) { System.out.println("账号"+param.get("id")); User user=new User(Long.valueOf(param.get("id")), param.get("userName"),param.get("password") ,Byte.valueOf(param.get("level")) ,param.get("institute") ,param.get("major") ,param.get("tel") ); System.out.println(user); service.insertUser(user); ResultVO<User> resultVO=new ResultVO<User>(0,"添加成功",null); return resultVO; }
controller中的代码可以执行,但出现HTTP Status 405 - Request method 'GET' not supported错误