Can I append an array to 'formdata' in javascript?
Writing as
var formData = new FormData;
var array = ['1', '2'];
for (var i = 0; i < array.length; i++) {
formData.append('array_php_side[]', array[i]);
}
you can receive just as normal array post/get by php.
How about this?
formdata.append('tags', JSON.stringify(tags));
... and, correspondingly, using json_decode
on server to deparse it. See, the second value of FormData.append can be...
a Blob, File, or a string, if neither, the value is converted to a string
The way I see it, your tags
array contains objects (@Musa is right, btw; making this_tag
an Array, then assigning string properties to it makes no sense; use plain object instead), so native conversion (with toString()
) won't be enough. JSON'ing should get the info through, though.
As a sidenote, I'd rewrite the property assigning block just into this:
tags.push({article: article, gender: gender, brand: brand});