How to pass arrays to sAjaxSource via aoData?

How to pass arrays to sAjaxSource via aoData?

arvinsimarvinsim Posts: 20Questions: 1Answers: 0
edited September 2011 in General
I have a sAjaxSource url that points to a PHP script that accepts a certain parameter as a $_POST array variable(Normally, this would represent checkboxes in a form).

My question is, how do I pass data in aoData in such a way that this will be accepted as an array in the PHP script? I tried this

[code]
aoData.push(
{
'name': 'ids',
'value': [1,2]
});
[/code]

and the PHP script interpreted this as a string( '1,2') as opposed to an array( [1,2] )

Replies

  • allanallan Posts: 63,531Questions: 1Answers: 10,475 Site admin
    Two options - first you can json_decode() the above array (possibly the easiest), or on the client-side you can do this (which is quite a handy feature of PHP at times):

    [code]
    aoData.push(
    {
    'name': 'ids[]',
    'value': 1
    },{
    'name': 'ids[]',
    'value': 2
    });
    [/code]

    Allan
  • arvinsimarvinsim Posts: 20Questions: 1Answers: 0
    I see. The solution with the "[]" worked. Apparently you need to have that at the end of the "name" in order to simulate checkboxes and the like.
This discussion has been closed.