FormData

XMLHttpRequest Level 2 adds support for the new FormData interface. FormData objects provide a way to easily construct a set of key/value pairs representing form fields and their values, which can then be easily sent using the XMLHttpRequest send() method.

It uses the same format a form would use if the encoding type were set to "multipart/form-data".

For details on how to use the FormData object, see Using FormData objects.

Syntax

new FormData ([in HTMLFormElement form])

Parameters

form
(optional) HTML Form Element <form> to send for keys/values. It will also encode file input content.

 

Method overview

void append(in DOMString name, in nsIVariant value);

Methods

append()

Appends a key/value pair to the FormData object.

void append(
  in DOMString name,
  in nsIVariant value
); 
Parameters
name
The name of the field whose data is contained in value.
value
The field's value. Can be a Blob , File , or a string, if neither, the value is converted to a string.
Notes

If you specify a Blob as the data to append to the FormData object, the filename that will be reported to the server in the "Content-Disposition" header will vary from browser to browser. See the Browser compatibility section for details.

Browser compatibility

  • Desktop
  • Mobile

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 7+ 4.0 (2.0) 10+ 12+ 5+
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 3.0 4.0 (2.0) ? ? ?

Gecko notes

Prior to Gecko 7.0 (Firefox 7.0 / Thunderbird 7.0 / SeaMonkey 2.4) , if you specified a Blob  as the data to append to the object, the filename reported in the "Content-Disposition" HTTP header was an empty string; this resulted in errors being reported by some servers. Starting in Gecko 7.0, the filename "blob" is sent.

Tags (3)

Edit tags

Attachments (0)

 

Attach file