Name

FormData — an HTTP multipart/form-data request body

Synopsis

The FormData type is a feature of XMLHttpRequest Level 2 (XHR2) that makes it easy to perform HTTP PUT requests with multipart/form-data encoding using an XMLHttpRequest. Multipart encoding is necessary, for example, if you want to upload multiple File objects in a single request.

Create a FormData object with the constructor, and then add name/value pairs to it with the append() method. Once you have added all of the parts of your request body, you can pass the FormData to the send() method of an XMLHttpRequest.

Constructor

new FormData()

This no-argument constructor returns an empty FormData object.

Methods

void append(string name, any value)

This method adds a new part, with the specified name and value, to the FormData. The value argument can be a string or a Blob (recall that File objects are Blobs).

Get JavaScript: The Definitive Guide, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.