Bug Tracker

Ticket #1538 (closed bug: wontfix)

Opened 1 year ago

Last modified 1 year ago

.ajax() data param not serializing array correctly

Reported by: scrasher Assigned to: anonymous
Type: bug Priority: major
Milestone: 1.2.1 Component: core
Version: 1.2 Keywords: ajax param serializing array
Cc: Needs: Review

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

Change History

Changed 1 year ago by john

  • status changed from new to closed
  • version changed from 1.1.4 to 1.2
  • resolution set to wontfix
  • milestone changed from 1.2 to 1.2.1

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.