Front section:
var data=[
{ "firstName":"John" , "lastName":"Doe" },{ "firstName":"Anna" , "lastName":"Smith" },
{ "firstName":"Peter" , "lastName":"Jones" }
]
$.ajax({
url: './saveSelectedData',
method: 'post',
data: { 'selectedData': JSON.stringify (data)}, // string passed as a common reference
dataType:"json",
error: function(data){
alert ( "failed");
},
success: function(data){
alert ( "success");
}
})
Background sections:
// json package used: com.alibaba.fastjson
@RequestMapping("/saveSelectedData")
@ResponseBody
public void saveSelectedData (String selectedData) {// Common string receiving
JSONArray jsonArray = JSONArray.parseArray (selectedData); // turn into arrays json
for (int i = 0; i <jsonArray.size (); i ++) // traverse the array json
{
JSONObject jsonObject = jsonArray.getJSONObject(i);
System.out.println (jsonObject.get ( "firstName")) // based on key values
}
}
ajax servlet code...
Receive foreground parameters In jsp, the parameters passed are: username=Armo. age=18. Way 1:Extract manually with req Way 2:Automatic injection of formal parameters The parameter name is the same as...
Solve ajax unable to receive array objects Problem Description: The front end sends the ajax array object; such as:{“tids”:["1","2","3"]}, The current station...
Background code: } AnswerRecord class: } Please indicate the source...
First of all, we need to introduce json scripts in the foreground to facilitate serialization of js objects <script type="text/javascript" src="/js/jquery.json-2.4.min.js">&l...
1. The demand is as follows 1. The front-end js encapsulates the List, initiates the request through ajax, and the backend processes the parameters through springboot. 2.js front-end data structure Js...
Original link: 0. Problem description When building springmvc, when the last step started to render the view, it was found that the data rendering failed. Controller layer: jsp: Background printing is...
When you do not use json format data, you still need to use the wrapper class: The user entity class is as follows: The code of the front page: The received code of SpringMVC in the background:...
JSP: var ProCtListStr = JSON.stringify(ProCtList); $.ajax({ url:“/addProductCategory.do” // POST request type:‘post’, // Metrophawei name does not write data:ProCtListStr, / / ...