Skip to main content

Bug Tracker

Side navigation

#1371 closed enhancement (invalid)

Opened July 07, 2007 04:06PM UTC

Closed May 12, 2008 01:13AM UTC

Last modified May 13, 2008 05:30PM UTC

jQuery.param when a value is an Array (improvement)

Reported by: adrien Owned by:
Priority: minor Milestone: 1.2.4
Component: core Version: 1.1.3
Keywords: param Cc:
Blocked by: Blocking:
Description

In the function jQuery.param, when "the value is an array then the key names need to be repeated", it's true, but we need to indicate this was an array then around line 2000:

if ( a[j] && a[j].constructor == Array )
	jQuery.each( a[j], function(){
		s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) );
	});

should be

if ( a[j] && a[j].constructor == Array )
	jQuery.each( a[j], function(){
		s.push( encodeURIComponent(j) + "[]=" + encodeURIComponent( this ) );
	});
Attachments (0)
Change History (5)

Changed July 07, 2007 05:53PM UTC by jakecigar comment:1

although a nice idea... it would break every server program!

It's the server's job to realize that it is an array.

Changed July 08, 2007 01:14AM UTC by adrien comment:2

Replying to [comment:1 jakecigar]:

although a nice idea... it would break every server program! It's the server's job to realize that it is an array.

I agree with that, but without the hack i submitted it's impossible through GET or POST to know that the values sent are an array!

The server can't tell that 'key' is an array in the following GET request:

http://example.com/?key=value1&key=value2&key=value3...

The request MUST be http://example.com/?key[]=value1&key[]=value2&key[]=value3...

When jQuery serialize a form with $.param, the key names used are the 'input' names, so it respect the form logic, if the names are 'key[]', it will send an array, if the names are 'key', it will send a string overridden by the last value.

But in the case of an array inside an object (the specific case my hack rely to), the key name will be always the same i.e. the object property name, and cannot be 'key[]' because an object property name can't contain brackets!

Now you see the problem? I am clear? (sorry for my english, I'm french)

Changed July 08, 2007 08:55AM UTC by adrien comment:3

oooups, ok I finaly manage to have an object property name with brackets... so my ticket is not valid!

It can be closed

Changed May 12, 2008 01:13AM UTC by flesler comment:4

resolution: → invalid
status: newclosed

It'd be useful if you could tell how.

As far as I know about this (not that much) you can arrange your fields' names as:

<input name="key[0]" />
<input name="key[1]" />
<input name="key[2]" />

or

<input name="key[name]" />
<input name="key[surname]" />
<input name="key[age]" />

This should be recognized (at least by PHP) as an array and will play nicely with $.param.

Changed May 13, 2008 05:30PM UTC by flesler comment:5

milestone: 1.1.41.2.4