Silver89 Silver89 - 7 months ago 40
Javascript Question

How to add an array value to new FormData?

On form submission I'm using jQuery to gather data including files and creating a FormData Object of the form values using:

var formData = new FormData($("form#formid")[0]);


but how can I add another value and it's key to this FormData Object?

Answer
var formData = new FormData($("form#formid")[0]);
formData.append("key", "value")

See https://developer.mozilla.org/en/XMLHttpRequest/FormData