Convert JS Object to form data

If you have an object, you can easily create a FormData object and append the names and values from that object to formData.

You haven’t posted any code, so it’s a general example;

var form_data = new FormData();

for ( var key in item ) {
    form_data.append(key, item[key]);
}

$.ajax({
    url         : 'http://example.com/upload.php',
    data        : form_data,
    processData : false,
    contentType : false,
    type: 'POST'
}).done(function(data){
    // do stuff
});

There are more examples in the documentation on MDN

Leave a Comment