Skip to main content

Bug Tracker

Side navigation

#1538 closed bug (wontfix)

Opened August 26, 2007 04:46PM UTC

Closed September 15, 2007 03:42AM UTC

.ajax() data param not serializing array correctly

Reported by: scrasher Owned by:
Priority: major Milestone: 1.2.1
Component: core Version: 1.2
Keywords: ajax param serializing array Cc:
Blocked by: Blocking:
Description

if you create data object with an array item and pass it to jquery, jquery does not serialize it correctly:

var myData = new Object;

myData.somearray = new Array();

myData.somearray[0] = "val1";

myData.somearray[1] = "val2";

$.ajax(...data: myData...)

will result in a query string with only one value of somearray being passed in (somearray=val2) instead of what it should be (somearray[]=val1&somearray[]=val2).

The bug is in the param function. To fix this REPLACE:

If the value is an array then the key names need to be repeated

if ( a[j] && a[j].constructor == Array )

jQuery.each( a[j], function(){

s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) );

});

WITH:

If the value is an array then the key names need to be repeated

if ( a[j] && a[j].constructor == Array )

jQuery.each( a[j], function(){

s.push( encodeURIComponent(j+"[]") + "=" + encodeURIComponent( this ) );

});

Attachments (0)
Change History (1)

Changed September 15, 2007 03:42AM UTC by john comment:1

milestone: 1.21.2.1
resolution: → wontfix
status: newclosed
version: 1.1.41.2

jQuery's data argument is only designed to serialize data of a specific structure, namely:

  [ { name: "name", value: "value" }, { name: "name", value: "value" }, ... ]

We can't really make any guarantees for anything else, at this time.