Simple-Ajax-Uploader icon indicating copy to clipboard operation
Simple-Ajax-Uploader copied to clipboard

"Data" option : not working with multi-dimensional arrays

Open theredled opened this issue 8 years ago • 9 comments

Hi, When you put "{args:{name: 'test', address: 'test'}}" as "data" argument, it is sent as "{args:'Object [object]'}".

Also, writing a query string in "data" could be an alternative, but it doesn't work either.

theredled avatar Dec 12 '16 02:12 theredled

Thanks for bringing this up. Any suggestions for addressing this? Perhaps using JSON.stringify?

LPology avatar Dec 23 '16 23:12 LPology

I don't think so, it should send the data as if it was a form, in a proper querystring format... With Jquery, it would be querystring = $.param(data); With plain JS, you have write a recursive function using encodeURIComponent()...

theredled avatar Dec 24 '16 00:12 theredled

There is actually a method in the plugin that does that, ss.obj2string(). I'll work on an update.

LPology avatar Dec 24 '16 00:12 LPology

Maybe you could also check if data is a string, and then send it "as is" ?

theredled avatar Dec 24 '16 00:12 theredled

That's what I was planning, only processing the input if it's not a string.

LPology avatar Dec 24 '16 00:12 LPology

Can you test this and see if it works?

http://pastebin.com/MFsmFay4

LPology avatar Dec 24 '16 00:12 LPology

Sorry not working on PHP side! JS Data : data: {args: 'blablabla', test: {a: 1, b: {c: 'test'}}}

POST data :

------WebKitFormBoundaryA4pVRKiPAXg3Bpl9
Content-Disposition: form-data; name="args"

blablabla
------WebKitFormBoundaryA4pVRKiPAXg3Bpl9
Content-Disposition: form-data; name="test"

a=1&b%5Bc%5D=test

should be (I guess):

------WebKitFormBoundaryA4pVRKiPAXg3Bpl9
Content-Disposition: form-data; name="args"

blablabla
------WebKitFormBoundaryA4pVRKiPAXg3Bpl9
Content-Disposition: form-data; name="test[a]"

1
------WebKitFormBoundaryA4pVRKiPAXg3Bpl9
Content-Disposition: form-data; name="test[b][c]"

test

(Because it's actually multipart and not normal POST)

theredled avatar Dec 24 '16 01:12 theredled

From the PHP side, what is the expected result? In other words, how should the variables be accessible in PHP?

LPology avatar Dec 24 '16 01:12 LPology

Expected result:

$_POST == array(
  'args' => 'blablabla',
  'test' => array('a' => 1, 'b' => array('c' => 'test'))
);

Got:

$_POST == array(
  'args' => 'blablabla',
  'test' => 'a=1&b%5Bc%5D=test'
);

theredled avatar Dec 26 '16 19:12 theredled