4

I'm using the following code to make a post.

var checked = ["2231","2432"];

jQuery.ajax({
            type: 'post',
            url: statusUrl,
            data: {"entries":checked},
...

However, when it actually posts, Post Data on server side and inspection in developer tools is always

 {entries[]: 2342 etc}

Why are the square brackets appearing? How can I get rid of it?

blue_zinc
  • 2,410
  • 4
  • 30
  • 38
  • 1
    The brackets are an indicator to the server for it to expect multiple similarly named parameters that should form an array or list. this is pretty standard, however, you can change the way it's done by setting the `traditional` setting to true. http://api.jquery.com/jquery.ajax – Kevin B Oct 19 '15 at 21:52
  • @KevinB Thanks! That works. If you write that as an answer I'll accpet it. – blue_zinc Oct 19 '15 at 22:41
  • Possible duplicate of [JQuery parameter serialization without the bracket mess](https://stackoverflow.com/questions/2540827/jquery-parameter-serialization-without-the-bracket-mess) – Munim Munna Apr 11 '18 at 20:52

1 Answers1

1

The brackets are an indicator to the server for it to expect multiple similarly named parameters that should form an array or list. this is pretty standard, however, you can change the way it's done by setting the traditional setting to true. http://api.jquery.com/jquery.ajax

Kevin B
  • 94,570
  • 16
  • 163
  • 180