5
$.ajax({ url:"SomeURL", data: { fields : ["field1", "field2"], }, success: function(data) { } }); 

Getting this in the server:

name = fields[] , VALUE = field1 name = fields[] , VALUE = field2 

(note the brackets)

Is that a bug? (This starting to happen after I upgraded to 1.5)

Thanx

2
  • 1
    I'm afraid I don't quite understand your question - Where in the "server" are you seeing that? and what is processing the AJAX request? Commented Feb 22, 2011 at 16:36
  • The server is tomcat apache and the "Getting this in the server" part represent the name and value of the parameters that are send with the requests. Commented Feb 23, 2011 at 8:12

1 Answer 1

7

It is not a bug, the serialization changed (but already in jQuery 1.4). Have a look at the traditional option:

traditional Boolean
Set this to true if you wish to use the traditional style of param serialization.

And from jQuery.param() (also have a look at the example):

As of jQuery 1.4, the $.param() method serializes deep objects recursively to accommodate modern scripting languages and frameworks such as PHP and Ruby on Rails. You can disable this functionality globally by setting jQuery.ajaxSettings.traditional = true;.

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

4 Comments

I already looked at the traditional option and still I'm getting the brackets in the end of the parameter's name. Do you know of a way of getting the parameter name without brackets?
I just rechecked my code and it turns out I put the traditional in the wrong place. So thank you for your help and sorry for wasting your time.
Is there a way to also set traditional when using getJSON() rather than ajax()?
@hippietrail: As the last sentence in the quoted documentation says, you can set jQuery.ajaxSettings.traditional = true;. Or instead of passing the object directly to getJSON, you can pass the result of $.param(obj, true).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.