Accessing FormData Values

后端 未结 11 830
误落风尘
误落风尘 2020-12-08 07:48

I have a FormData object which I create in javascript from an HTML form like so. The FormData object doesn\'t seem very well documente

11条回答
  •  执念已碎
    2020-12-08 08:02

    First thing I don't think it's possible to build a FormData object from a form as you've specified, and to get values from the form use the method described in the accepted answer -- this is more of an addendum!

    It looks like you can get some data out of a FormData object:

    var formData = new FormData();
    formData.append("email", "test1@test.com");
    formData.append("email", "test2@test.com");
    formData.get("email");
    

    this will only return the first item for that key, in this case it will return 'test1@test.com', to get all the email addresses use the below code

    formData.getAll("email")
    

    Please see also: MDN article on formdata get method.

提交回复
热议问题