springMVC, foreground ajax pass JSON array parameters, how to receive background

 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
    }
}

Intelligent Recommendation

[SpringMVC] [Receive foreground parameters] [Transfer parameters to the foreground]

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...

How can't ajax submit background receive json array object

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...

The entity received in the background contains List, how does the foreground Ajax pass parameters

Background code: } AnswerRecord class: } Please indicate the source...

How to pass data through json in the foreground script to the background (using Microsoft's own ajax)

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...

More Recommendation

Ajax - pass list array, springboot receive parameters

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...

In SpringMVC, Model is used to pass parameters, the background is normal, but the foreground is unsuccessful.

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...

How to transfer userList from the foreground to the background and receive it by SpringMVC?

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:...

SpringMVC Processing Receive AJAX Request Receive JSON, List Type Parameters

JSP: var ProCtListStr = JSON.stringify(ProCtList); $.ajax({ url:“/addProductCategory.do” // POST request type:‘post’, // Metrophawei name does not write data:ProCtListStr, / / ...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top