We now require a function named submitHero() , which is called when the form is
submitted. In this function we grab a reference to the form using the event.target
property (since it was the form that was submitted) and create a new instance of the
FormData() constructor function, providing the form as an argument. This does all the
hard work for us; after this, we submit the form using Ajax as before, but provide the form
data instances (stored in the data variable) as an argument of the send() method.
It's also possible to add data to the form data instance as key-value pairs using the ap-
data = new FormData(); // no form provided as an argument
↵ empty form data instance
The FormData interface interface really comes into its own when a form contains files to
upload. This was a notoriously difficult task in the past, often requiring the use of Flash or
another third-party browser plugin to handle the upload process. The FormData instance
will automatically create the necessary settings required and take care of all the hard work
if any file uploads are present in the form.
You can find more information about the FormData interface in this SitePoint article by
Craig Buckler and on the Mozilla Developer Network.
Search WWH ::