Skip to main content

Bug Tracker

Side navigation

#2950 closed bug (invalid)

Opened May 29, 2008 07:37AM UTC

Closed January 08, 2009 04:26AM UTC

Not supproted multi-dimensional objects on jQuery.ajax options.data

Reported by: aiky Owned by:
Priority: major Milestone: 1.3
Component: ajax Version: 1.2.5
Keywords: Cc:
Blocked by: Blocking:
Description

options.data = {

a: 'a',

b: 'b',

c: {

d: 'd',

e: 'e'

}

}

POST:

a a

b b

c [object+Object]

Attachments (0)
Change History (6)

Changed May 29, 2008 11:55PM UTC by flesler comment:1

What would you expect the result to be ?

Changed May 31, 2008 08:59AM UTC by aiky comment:2

I need to receive on server side:

array(

a=>'a',

b=>'b',

c=>array(

d=>'d',

e=>'e'

)

)

as realised in JsHttpRequest

Changed June 10, 2008 07:21PM UTC by ygirouard comment:3

You can do something like this though:

options.data = {
    a: 'a',
    b: 'b',
    c[d]: 'd',
    c[e]: 'e'
}

And on the server-side, the POST request would automatically see c as an array of values.

I do this to pass an array of checkboxes to a php script, the name of each input is something like "input_name[some_index]". Then in php, $_REQUEST["input_name"] becomes an array where "some_index" becomes the key.

I do agree though that it should accept multi-dimensional objects as well though, it makes it much easier.

Changed June 16, 2008 06:06AM UTC by aiky comment:4

Yes, may to find some ways for emulating multi-dimensional objects.

But would be most corretly to use multi-dimensional objects transparent by core level of jQuery as JSON is multi-dimensional data format and much using in AJAX interactions.

Changed June 16, 2008 02:33PM UTC by aiky comment:5

Ok. Next code translating multi-dimensional object to simple list and can be include to jQuery core for transparent using multi-dimensional objects:

var object2list = function(object, list, _key){
  if(!list) var list = {};
  for(var key in object){
    if(!_key) var _key_ = key;
    else var _key_ = _key + '[' + key + ']';
    if(typeof(object[key]) != 'object') list[_key_] = object[key];
    else list = object2list(object[key], list, _key_);
    object[key] = null;
  }
  return list;
}

Changed January 08, 2009 04:26AM UTC by dmethvin comment:6

resolution: → invalid
status: newclosed

http://docs.jquery.com/Ajax/jQuery.ajax#options

Object must be Key/Value pairs. If value is an Array, jQuery serializes multiple values with same key i.e. {foo:["bar1", "bar2"]} becomes '&foo=bar1&foo=bar2'.