spring - How to send Array & Set datatype data in AJAX call? -


i have spring api

@requestmapping(value="setentry/{userid}/{columnname}", method = requestmethod.post) public responseentity<?> updateusersettypefields(@pathvariable string userid,              @pathvariable string columnname, @requestbody collectionrequestparams entries ,                 httpservletrequest request) {  

here collectionrequestparams

public class collectionrequestparams {     private string[] arr;     private set set;     // setter & getter 

i trying call api :

$.ajax({                 url:"setentry/123/111",                 headers:{"x-accesskey":"token","x-deviceid":"123"},                 data:{"arr":['111','222']},                 type:"post",contenttype:"application/json"             }) 

this throwing http status 400 question how can pass arguments arr & set i.e sending string[] & set datatype data ?

when use @requestbody means body of request , try parse , map parameter class.

in case need json like

{"arr" : ["1", "asd", "45"], "set" : ["123", "222"]} has body of request. like:

$.ajax({     url:"setentry/123/111",     headers:{"x-accesskey":"token","x-deviceid":"123"},     data: json.stringify({"arr":['111','222']}),     type:"post",contenttype:"application/json" }) 

you have stringify whole object.

also don't use non generic set, it's bad practice. change set ot whatever type need.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -