Using jquery's AJAX approach to submitting
The first, submitted as a JSON object
var jsondata = {"Name": "Zhangsan", "Sex": "Boy"};$.ajax ({type: "POST", url: "Test_post1", data:jsondata,//success:f Unction (data) {alert (data);}});
If the data returned by the request is in JSON format, then there are attributes: DataType: ' JSON '
@RequestMapping (value = "/test_post1", method = Requestmethod.post) @ResponseBodypublic resultdto test_post1 ( HttpServletRequest request, User user) {resultdto result = new Resultdto (); return result;}
Using @responsebody, the JSON string returned in response is the corresponding format.
The second, submitted as a JSON string
var jsondata = {"Name": "Zhangsan", "Sex": "Boy"};$.ajax ({type: "POST", url: "Test_post2", Data:JSON.stringify (Jsondata ), ContentType: ' Application/json ', success:function (data) {alert (data);}});
@RequestMapping (value = "/test_post2", method = Requestmethod.post) @ResponseBodypublic resultdto test_post2 ( HttpServletRequest request, @RequestBody Jsonobject jsonobject) {resultdto result = new Resultdto (); return result;
Using jquery's post to submit
var jsondata = {"Name": "Zhangsan", "Sex": "Boy"};$.post ("Test_post3", Jsondata, function (data) {alert (data);});
@RequestMapping (value = "/test_post3", method = Requestmethod.post) @ResponseBodypublic resultdto test_post3 ( HttpServletRequest request, User user) {resultdto result = new Resultdto (); return result;}
Note:
If the data returned by the request is in JSON format, use the following notation to request the data:
$.post ("Test_post3", Jsondata, function (data) {alert (data);}, ' json ');
Spring MVC Ajax Submission Method