Skip to content
Advertisement

How to combine two javascript FormData objects

I need to combine two FormData objects and post them using XMLHttpRequest. One of the forms contains file input.

JavaScript

It doesn’t work when I use $.extend or if I use serialize() to combine the form that doesn’t have file input. Any idea how to do this?

Advertisement

Answer

You cannot couldn’t. FormData is was unfortunately not enumerable.

However, as you say only one of your forms does contain a file input. Then it should be possible to use serializeArray on the other and append to the data manually:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement