1

In the following code when I pass static value in testArr for instance, [2, 3]; I get testArr[0] => 2 and testArr[1] => 3 which is correct. However if I pass dynamic value to testArr for instance test; I get testArr[0] => 2,3. I could not figure out the problem. Please help.

 var test = '1' + ',' + '2'; $.ajax({ url : url, type : "post", data : { 'testArr[]' : [test] }, success : function(response) { alert(response); } }); 
1
  • you're sure you're not getting testArr[0] => '1,2' ? as that is what you are sending, a string with a one, a comma and a two! Commented Apr 16, 2013 at 21:46

1 Answer 1

3

Right now you are passing test as a string. You want to instead pass it like below:

var test = new Array(1,2); 

Then just pass test without the brackets.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.