And turn SpringMvc ajax get, post springMVC traditional values in pit pit ajax get request, and the requested parameter passing and post

ajax get request springMVC the pit and the post request parameter passing and

1, ajax request whether to post, or get, url in with? In the form of parameters, the background to be able to receive a variable of type String, variable names and parameter names must match

Reception ajax:

$.ajax(

"productForm? loginname2 = jichen", URL string // request was sent.
{
DataType: "JSON", // expected data type returned by the server. If the server returns inconsistent, reported the parseError
type: "POST" or "get", // GET or POST request method
content type when encoding, // send information to a server; "charset = UTF-8 application / json": contentType

。。。

});

Background springMVC:

@ RequestMapping (value = "/ ProductForm")
@ResponseBody (This annotation means that the return value of this method is not a page name, but with a request to return body (that is, the server returns data to the client))
public String ProductPost (String loginname2) {
                                        (here must match the parameter names and pass the front desk)


System.out.println (loginname2); values of the print is Jichen

}

 

2, ajax request is a post, contentType must be "application / json; charset = UTF-8", data must be formatted with JSON.stringify: JSON.stringify ({id: 1}), the Map with the type of background can! requestBody Map data is received, indispensable;

 

Reception ajax:

$.ajax(

"productForm? loginname2 = jichen", URL string // request was sent.
{
Type: "POST", 
contentType: "file application / JSON; charset = UTF-. 8", // encoding type when transmitting content information to the server, charset if not, the background of Chinese spread distortion

is sent to the server // The data.
data: JSON.stringify ({id: 1 , loginname: "Spring MVC real business applications"})

}

Background springMVC:

@ RequestMapping (value = "/ ProductForm")
@ResponseBody (This annotation means that the return value of this method is not a page name, but with a request to return body (that is, the server returns data to the client))
public String ProductPost (String loginname2, @ requestBody Map data) {
                                       

System.out.println (data.get ( "loginname") ); print out the actual enterprise application Spring MVC


}

1, ajax request whether to post, or get, url in with? In the form of parameters, the background to be able to receive a variable of type String, variable names and parameter names must match

Reception ajax:

$.ajax(

"productForm? loginname2 = jichen", URL string // request was sent.
{
DataType: "JSON", // expected data type returned by the server. If the server returns inconsistent, reported the parseError
type: "POST" or "get", // GET or POST request method
content type when encoding, // send information to a server; "charset = UTF-8 application / json": contentType

。。。

});

Background springMVC:

@ RequestMapping (value = "/ ProductForm")
@ResponseBody (This annotation means that the return value of this method is not a page name, but with a request to return body (that is, the server returns data to the client))
public String ProductPost (String loginname2) {
                                        (here must match the parameter names and pass the front desk)


System.out.println (loginname2); values of the print is Jichen

}

 

2, ajax request is a post, contentType must be "application / json; charset = UTF-8", data must be formatted with JSON.stringify: JSON.stringify ({id: 1}), the Map with the type of background can! requestBody Map data is received, indispensable;

 

Reception ajax:

$.ajax(

"productForm? loginname2 = jichen", URL string // request was sent.
{
Type: "POST", 
contentType: "file application / JSON; charset = UTF-. 8", // encoding type when transmitting content information to the server, charset if not, the background of Chinese spread distortion

is sent to the server // The data.
data: JSON.stringify ({id: 1 , loginname: "Spring MVC real business applications"})

}

Background springMVC:

@ RequestMapping (value = "/ ProductForm")
@ResponseBody (This annotation means that the return value of this method is not a page name, but with a request to return body (that is, the server returns data to the client))
public String ProductPost (String loginname2, @ requestBody Map data) {
                                       

System.out.println (data.get ( "loginname") ); print out the actual enterprise application Spring MVC


}

Guess you like

Origin www.cnblogs.com/fc520/p/11881439.html