LPology / Simple-Ajax-Uploader

Javascript file upload plugin with progress bar support. Works in all major browsers, including IE7+, Chrome, Firefox, Safari, and Opera. No dependencies - use it with or without jQuery.
995 stars 267 forks source link

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

Open theredled opened 7 years ago

theredled commented 7 years ago

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.

LPology commented 7 years ago

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

theredled commented 7 years ago

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

LPology commented 7 years ago

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

theredled commented 7 years ago

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

LPology commented 7 years ago

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

LPology commented 7 years ago

Can you test this and see if it works?

http://pastebin.com/MFsmFay4

theredled commented 7 years ago

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)

LPology commented 7 years ago

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

theredled commented 7 years ago

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