오현준 오현준 - 6 months ago 39
Javascript Question

FormData append doesn't work

In jQuery code,

var formData = new FormData($('#content-submit')[0]);
formData.append("Title", $("input[name=Title]").val());
formData.append("Url", $("input[name=Url]").val());
formData.append("Content", $("textarea[name=Content]").text());
formData.append("Genre", $("input[name=Genre]").val());
formData.append("File", $("input[name=File]")[0].files[0]);
console.log(formData);


But console.log says

FormData {}


So I think that FormData append method doesn't work. Are there other things that I should do?

Answer

FormData can't be inspected from the web developer console. You can only use them to create key value pairs to be sent.

If you want to debug it, you may do this,

for (var p of formData) {
  console.log(p);
}