appending array to FormData and send via AJAX

The Solution to appending array to FormData and send via AJAX is


You can also send an array via FormData this way:

var formData = new FormData;
var arr = ['this', 'is', 'an', 'array'];
for (var i = 0; i < arr.length; i++) {
    formData.append('arr[]', arr[i]);
}

So you can write arr[] the same way as you do it with a simple HTML form. In case of PHP it should work.

You may find this article useful: How to pass an array within a query string?

~ Answered on 2015-02-10 14:59:16


Most Viewed Questions: