W3C home > Mailing lists > Public > public-webapps@w3.org > January to March 2010

Re: FormData questions

From: Jonas Sicking <jonas@sicking.cc>
Date: Sat, 13 Feb 2010 18:44:08 -0800
Message-ID: <63df84f1002131844t3e54f098t1319d4d2a0ade02b@mail.gmail.com>
To: Dmitry Titov <dimich@chromium.org>
Cc: Webapps WG <public-webapps@w3.org>
On Sat, Feb 13, 2010 at 6:02 PM, Dmitry Titov <dimich@chromium.org> wrote:
> On Fri, Feb 12, 2010 at 5:32 PM, Jonas Sicking <jonas@sicking.cc> wrote:
>>
>> Hi WebApps fans!
>>
>> Working on implementing FormData and ran into a couple of questions.
>>
>> First of all, I assume that it is intended that a FromData object can
>> be submitted several times. I.e. that the following code is ok:
>>
>> fd = new FormData;
>> fd.append("name1", "foo");
>> xhr1 = new XMLHttpRequest;
>> xhr1.open(...);
>> xhr1.send(fd);
>> fd.append("name2", "bar");
>> xhr2 = new XMLHttpRequest;
>> xhr2.open(...);
>> xhr2.send(fd);
>>
>> where the first XHR will send 1 name/value pair, and the second XHR
>> will send 2. I do think this should be allowed, but I wanted to make
>> sure others agreed.
>
> What can be a reason to disallow this? FormData is just a collection of data
> objects. So assuming those XHR objects are sync, the code should work as you
> described.

It complicates implementation a tiny amount, but IMHO not enough to disallow it.

> Interesting question though - what happens if XHR is async and the content
> of FormData changes while async operation is in progress. By analogy with
> scenario when underlying file of Blob object changes while async reading
> operation is in progress, would it be reasonable to fail the send and return
> 'error' ProgressEvent?

I don't think raising an 'error' event should be correct, no. In my
example above I think the two requests should succeed successfully,
and the first one should submit one name/value pairs, and the second
should submit two.

>> Second, what encoding should be used when submitting a FromData
>> object? A few options are:
>> * Always use UTF-8
>> * Allow a mimetype to be set on the FormData object, using a property
>> or constructor argument
>> * Use the charset mime parameter specified on the content-type header
>> set using xhr.setRequestHeader
>>
>
> Having a way to specify encoding could be only useful for writing client
> code against legacy site that takes charset-encoded form data and ignores
> the charset parameter of content-type header of the request. That seems rare
> these days. It would be way simpler to only deal with UTF-8, imo.

Does any browser include a charset parameter for multipart/form-data
submissions? Firefox does not and last we added it it broke a bunch of
sites IIRC. That was a while ago though.

/ Jonas
Received on Sunday, 14 February 2010 02:45:00 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:37 GMT