2
var sample=[]; sample.push("one"); sample.push("two"); sample.push("three"); $.ajax({ url : 'sampleAction', dataType : 'json', type : 'POST', data : { 'message':sample }, success:function(data){ } }); 

It have to pass this like enter image description here

But, it is pass with [] symbol, how to avoid this [] symbol enter image description here

3
  • This array symbol suggests the key of that array. Like one is on 0th (first) key and so on. Commented Jul 28, 2016 at 5:21
  • Why you want to remove that symbol? Commented Jul 28, 2016 at 5:23
  • in server side I get this parameter as arraylist... Commented Jul 28, 2016 at 5:26

2 Answers 2

1

I got an answer, If we give traditional: true, it works

$.ajax({ url : 'sampleAction', dataType : 'json', type : 'POST', data : sample, traditional: true, success:function(data){ 

} });

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

Comments

0

Here you are passing data as array, then it should pass with array symbol. For avoid array symbol you have to pass associative object without nested with message key. And in your server side script you need to change accordingly for grab posted data.

var sample=(); sample.one = "one"; sample.two = "two"; sample.three = "three"; $.ajax({ url : 'sampleAction', dataType : 'json', type : 'POST', data : sample, success:function(data){ } }); 

If you pass multiple messages then I am advising you to keep in array format because it is very easy to access it in server side.

1 Comment

yes i am sending multiple message, but in server side I get that as array lis, not array so I have to avoid [] symbol, previously I tried the same thing that time the parameter send without [] symbol...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.