Ajax is often used in front-end development to send asynchronous requests, and requests for post types are included with the request data. The two commonly used methods are: Form Data and Request Payload.
GET request
When a GET request is used, the parameters are stitched together in the form of a key=value after the requested URL. For example:
Http://m.baidu.com/address/getlist.html?limit=50&offset=0&t=1502345139870
However, limited by the length of the request URL, a GET request is used when there are fewer general parameters.
POST request
When the number of parameters is high and there is a certain security requirement for the data, consideration is given to passing the parameter data with the POST request. The parameter data for the POST request is in the request body.
Mode one: Form data forms
When the request header of the POST request is set to content-type:application/x-www-form-urlencoded (the default), the parameters are submitted in the form of the standard form data in the request body, with the & sign stitching, the parameter format is key= Value&key=value&key=value ...
Front-End Code settings:
Xhr.setrequestheader (' Content-type ', ' application/x-www-form-urlencoded '); Xhr.send (' a=1&b=2&c= 3 ');
In a servlet, the backend can get form parameters in the form of Request.getparameter (name).
Mode two: Request payload form
If you use the Ajax native POST request, the request header is set to Content-type:application/json, the requested parameter is displayed in the request payload, the format of the parameter is in JSON format: {"key": "Value", "Key" : "Value" ...}, which is more readable in this way.
The backend can be obtained using the Getrequestpayload method.
Form Data and Request Payload differences
If the request header is set to content-type:application/x-www-form-urlencoded, then this request is considered a form request, the parameter appears in the form data, the format is key=value&key= Value&key=value ...
The native Ajax request header is set to Content-type:application/json, or the default content-type:text/plain is used, and the parameters are presented in the request payload block.
Reference Documentation:
Http://www.cnblogs.com/btgyoyo/p/6141480.html
http://xiaobaoqiu.github.io/blog/2014/09/04/form-data-vs-request-payload/
The difference between the form data in the HTTP request and the request payload