Bug Tracker

Opened 16 years ago

Closed 16 years ago

#1538 closed bug (wontfix)

.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 ) );

});

Change History (1)

comment:1 Changed 16 years ago by john

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.

Note: See TracTickets for help on using tickets.