4

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?

2
  • What is the value of winnerList in your JS code? Commented Feb 4, 2015 at 13:11
  • i have defined as winnerList=[ ]; and later 10 numbers are stored in it Commented Feb 4, 2015 at 13:14

2 Answers 2

13

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)
Sign up to request clarification or add additional context in comments.

1 Comment

on doing this I am getting value like this [[112],[12],[114]] its something like list inside list so how to get only integer without splitting it from brackets ??
4

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]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.