jQuery ajax pass json array to the background

jQuery ajax pass json array to the background

The front end code is as follows:

function ajaxClick() {
    var arr = []
    var jsont = {"name": "hejinghuan", "age": "23"};
    var jsont2 = {"name": "yongzheng", "age": "33"};
    var jsont3 = {"name": "huangdi", "age": "34"};
    arr.push(jsont);
    arr.push(jsont2);
    arr.push(jsont3);
    $.ajax({ // ajax login request
        url: "ajaxdemo/test",
        type:"POST",
        data:{params:JSON.stringify(arr)},
        async:false,
        success:function(data){
            alert(data);
        }
    });
}

Background code:
Here is the params, which is data:{params:JSON.stringify(arr)}. The key of the aqx passed in the parameter. After receiving it, convert the string to JSON with fastjson. Array.

@RestController
@RequestMapping("/ajaxdemo")
public class ajaxController {

    @RequestMapping("test")
    public String ajaxparam(@RequestParam String params) {
        JSONArray paradms = JSON.parseArray(params);
        for (int i = 0; i< paradms.size();i++) {
            JSONObject paramjson = (JSONObject) paradms.get(i);
            String name = paramjson.getString("name");
            System.out.println(name);
        }
        System.out.println(params);
        return params;
    }
}

Intelligent Recommendation

Pass the array with ajax to the background: traditional: true,

Traditional:true, : Prevents deep serialization and prevents data from being available in the background...

ajax pass an array of issues from the foreground to the background

Hello Hello everyone: I still love Shenyangjava trainingThe Tsai, brought to you today is from the front desk ajax Detailed analysis and backstage pass to an array of problems. Welcome to the Markdown...

$ .Ajax pass a string to the background, background objects return json

Here is the record I am using ajax to send data to the background, do the corresponding business logic operations backstage after receiving the data; the great God is ignored, the spray would not have...

JQuery Ajax how to pass an array type parameter

Suppose the parameters that need to be passed to the background are: var userid = [1,2,3]; var username=["a","b","c"]; Var school = "Hahahahahaha"; There are tw...

More Recommendation

Ajax pass the array to the background, the background Spring MVC accepts an array of parameters

The front end of the following code, passing an array, receiving background List <String>: Background code as follows: There are two points to note: Use annotations@RequestParam Parameter values...

Reception pass json array, receiving and processing the background

Here the front desk pass over the json data format like this Here, if the background by directly receiving List is not enough, since the choice of solution and still a data array, direct access being ...

js array of values ​​to pass background processing (JSON)

Reproduced in: https: //my.oschina.net/u/3055303/blog/878944...

jQuery- use ajax() in jquery instead of traditional json to pass values

The tablejsontest.json code is as follows:...

Use ajax to dynamically load the background data json array into the list on several pages of the app made in jquery mobile

Later, I searched for information and found that although the data was loaded after the new node was added, the style was not loaded, so there are two points to note in the whole process. 1. Use loops...

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

Top