0

I´m making a call using javascript and I would like to send an array:

var selected = [];
selected=getAllEnginesIdsSelected();
    console.log("selected: "+selected);
    $.getJSON('/call/' + selected,
            function(myList) {

The funcion that I use in Javascript to retrieve array is:

function getAllEnginesIdsSelected() {

        var selected = [];

        $("input:checkbox[id^='engine_']:checked").each(function(){
            var ele=$(this)[0].id;
            selected.push(ele);
        });

        return selected;

    }

Console.log retrieves selected: 2,5

In MVC Controller I have

@RequestMapping(method = RequestMethod.GET, value = "/call/{selected}")
public List<List<myList>> myCall(@RequestParam(value="selected[]") String[] selected){

I gives an error. I don´t want to use AJAX. This is posible to send?

9
  • Unless I'm missing something, getAllEnginesIdsSelected() is always going to return an empty array. Commented Oct 19, 2016 at 15:10
  • You don't want to use Ajax you say? $.getJSON uses Ajax. Commented Oct 19, 2016 at 15:11
  • Btw you can totally drop this: selected = []; in the first code snippet. You can directly assign the method to the variable. Commented Oct 19, 2016 at 15:12
  • I didn ´t know Tom. David W, I edited the code. Commented Oct 19, 2016 at 15:12
  • You can't use getJSON to send data. You'd be better off using $.post(). Commented Oct 19, 2016 at 15:15

1 Answer 1

1

selected is an array, which you are joining to a string in the URL. Try something like $.getJSON('/call/?selected=[' + selected.join(',')]

Sign up to request clarification or add additional context in comments.

1 Comment

I make toString of array and I sent the values :)

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.