Posting array using formdata

Try this. It worked for me.

var files = $scope.myFile;
        var fd = new FormData();
        fd.append("file", files[0]);
        fd.append("assignment", JSON.stringify({ classAssignment: $scope.editItem }));

From your syntax, you appear to be trying to pass an object, not an array. I don't think you can pass objects through HTML form.

{ key1 : value1 , key2 : value2 }

vs

[ value1, value2 ]

This is a handy reference to general JS syntax


Thanks. I now came up with this solution:

                for (i = 0; i < social_networks.length; i++) {
                    formData.append("myarray["+i+"][mykey]",arr[i]['mykey']);
                    formData.append("myarray["+i+"][mykey2]",arr[i]['mykey2']);
                }

Using .append() on each element of the associative array might produce the results you're expecting.

In place of this line:

formData.append('myarray',{key1: 'bla', key2: 'blubb'});

You might try the following:

var myarray = {key1: 'bla', key2: 'blubb'};

jQuery.each(myarray, function(key, value) {
    formData.append('myarray['+key+']', value);
});