0

Here's my form:

    <form id="content-add-form" role="form" name="content-add-form" enctype="multipart/form-data">

I'm trying to get form data using:

var formData = new FormData($('#content-add-form'));

But it's not working, any ideas why?

1 Answer 1

3

Try this

var formData = new FormData($('#content-add-form')[0]);

You need to pass the actual form element - not the jQuery object containing it.

https://developer.mozilla.org/en-US/docs/Web/API/FormData

Constructor

new FormData (optional HTMLFormElement form)

As for why you can't see the data, read here: How to inspect FormData?

Working example: http://jsfiddle.net/TGzRa/

Sign up to request clarification or add additional context in comments.

4 Comments

Actually, this still does not work. I can now get out anything I append to form data, but not the data I intialize it with.
@panthro Well, it will always be a snapshot of the form in its current state.
Yes, I have fillied in data, nothing is coming through
@panthro My test is working fine. See the update. I think your problem lies elsewhere

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.