1. Encapsulation of AJAX data
var json = {"token": token};//Encapsulating JSON Data$.ajax ({URL:‘‘, Data:JSON.stringify (JSON),//encapsulated as JSONDataType: "JSON", type:"POST", Async:false, Cache:false, ContentType:' Application/json;charset=utf-8 ',//must be addedsuccess:function (data) {}, Error:function (data) {textmsg ("Request error, please contact customer service staff!" "); } });
2. Background reception
@ResponseBody @RequestMapping ("Checklogin") public String checklogin (HttpServletRequest request,httpservletresponse response, @RequestBody jsonobject jsonobject) { System.out.println ("----------------I am Checklogin"); String token = Jsonobject.get ("token") = =null? "": Jsonobject.getstring ("token"); // or use String token = Request.getparameter ("token") ==null? ": Request.getparameter (" token ");}
Ajax transmits JSON data, SPRINGMVC JSON data in the background