I have a array that contains an array of 10 number in jquery named "winnerList" I am sending it to WinnerController from jquery using ajax as :
$.ajax({
url: "/demoapp/winner/winners",
type: "POST",
data: { "winnerList": winnerList },
success: function(data) {
alert("Successfully sent winnerList")
},
});
Now I am receiving it inside controller using "winners" function as:
def winners(){
print params
}
I am getting result as :
[winnerList[0][]:076, winnerList[1][]:118,winnerList[2][]:102, .....winnerList[9][]:18, action:winners, format:null, controller:winner]
But I wanted a result of only numbers not this type of structure which i could not access. Can anyone help?
First convert your array to json when send it:
...
data: { "winnerList": JSON.stringify(winnerList) },
...
Then in the action parse this json:
def slurper = new JsonSlurper()
def result = slurper.parseText(params.winnerList)
I got a solution for my own question.... In jquery:
............
data: { "winnerList": JSON.stringify(winnerList) },
.......
In controller:
...............
def listWinnerIds= JSON.parse(params.winnerLists)
..............
this will give the values in a list like [1,2,3]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With