Hemachandra Hemachandra - 1 year ago 100
JSON Question

How to pass array in jquery ajax call and how to receive same from spring mvc controller

I am calling spring mvc controller method using jquery ajax.

jquery ajax call:

var filters = {KPI : visual, partnerName: params['partnerName'], itemQualifier: getItemQualifier(), currency : getCurrency(), sellSide: getSellSide()};

type: "POST",
url: "/reports/savefilters",
data: filters,
success: function(response){
alert('success: ' + response);
error: function(e){
alert('Error: ' + e.message);

Spring mvc code:

public void saveFilters(@RequestParam("KPI") String KPI, @RequestParam("partnerName") String partnerName,
@RequestParam("itemQualifier") String itemQualifier, @RequestParam("currency") String currency,
@RequestParam("sellSide") String sellSide){

Its working fine without "@RequestParam("partnerName") String partnerName" parameter.

Here "params['partnerName']" values are like abc,def,ghi.

Am I not sending data properly to controller???
Any suggestions how to make it work???. Thanks...

Answer Source


@RequestParam("partnerName") String partnerName


@RequestParam(value = "partnerName[]", required = false) String[] partnerName
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download