1.jsp page
functionOnsaveclick (BTN) {//Save$.ajax ({URL:"", type:"POST", Data: $ ("#form"). Serialize (), the data sent to the server must be in the Key/value format for example: {"AA": $ ("#id"). Val ()}, DataType:' JSON ', the data type returned by the server success:function(data) {if(data.success = = ' true ') {alert (' Operation succeeded! '); } Else{alert (' Operation failed: ' +data.msg); }}, Error:function() {alert ("Network Error"); } }); }
2. Backstage (two kinds of return page data)
// Save @RequestMapping ("/save") @ResponseBody public String Save (User user) { Try { //Operation return "{\" success\ ": \" true\ "}"; Catch (Exception e) { e.printstacktrace (); return "{\" success\ ": \" false\ ", \" msg\ ": \" "+ e.getmessage () +" \ "}"; } }
//Save@RequestMapping (Value= "/save") @ResponseBody PublicObject Save (user user){Map<String,Object> map =NewHashmap<string, object>(); Try{String ID=meetingservice.save (form). GetId (); Map.put ("Success",true); }Catch(Exception e) { //Operation Map.put ("Success",false); Map.put ("MSG", E.getmessage ()); } returnmap; }
JQuery Ajax-ajax () method