HTML 用户代理是否需要按特定顺序提交表单数据?
对于给定的 HTML 表单,是否需要用户代理以特定顺序构建提交请求?
我正在查看 HTML 4.0.1 规范,它似乎没有指定“成功控件”成为提交请求的一部分的顺序。 第 17.13.3 节,处理表单数据,指出:
当用户提交表单(例如,通过激活提交按钮)时,用户代理按如下方式处理它。
第一步:识别成功的控制
第二步:构建表单数据集
第三步:对表单数据集进行编码
然后根据
FORM
元素的enctype
属性指定的内容类型对表单数据集进行编码。第四步:提交编码后的表单数据集
在第二步中,表单数据集被描述为一个序列,因此其在步骤3中编码的顺序大概是固定的。但是,这引出了一个问题:表单数据集中成功控制的顺序是什么。
例如,给定以下 HTML 表单:
<form action="#" method="GET">
<input type="hidden" name="key1" value="value1" />
<div>
<div>
<input type="hidden" name="key2" value="value2" />
</div>
<input type="hidden" name="key3" value="value3" />
<input type="submit" name="submit" value="Submit" />
</div>
<input type="hidden" name="key5" value="value5" />
</form>
表单数据集可以是
[ (
"key1"
,"value1"
), ("key2"
,"value2"
), ("key3"
,"value3"
), ("提交"
,"提交"
), ("key5"
,“值5”
)]
(即 DOM 的深度优先搜索);或者
[ (
"key1"
,"value1"
), ("key5"
,"value5"
), ("key3"
,"value3"
), ("提交"
,"提交"
), ("key2"
,“值2”
)]
(广度优先搜索);或者甚至是通过迭代随机哈希表中的控件名称/当前值对而产生的不确定顺序?
使用 IE 9 和 Firefox 9.0.1 测试此表单,似乎都使用深度优先搜索顺序。也许其他浏览器有所不同。问题是这个命令是否是在某个地方规定的。
For a given HTML form, is a user agent required to build the submit request in a particular order?
I was looking through the HTML 4.0.1 Specification and it doesn't seem to specify the order that "successful controls" become part of the request on submission. Section 17.13.3, Processing form data, states:
When the user submits a form (e.g., by activating a submit button), the user agent processes it as follows.
Step one: Identify the successful controls
Step two: Build a form data set
A form data set is a sequence of control-name/current-value pairs constructed from successful controls
Step three: Encode the form data set
The form data set is then encoded according to the content type specified by the
enctype
attribute of theFORM
element.Step four: Submit the encoded form data set
At step two, the form data set is described as a sequence, so the order in which it is encoded in Step 3 is presumably fixed. But, this begs the question of what the order of successful controls is in the form data set.
For example, given the following HTML form:
<form action="#" method="GET">
<input type="hidden" name="key1" value="value1" />
<div>
<div>
<input type="hidden" name="key2" value="value2" />
</div>
<input type="hidden" name="key3" value="value3" />
<input type="submit" name="submit" value="Submit" />
</div>
<input type="hidden" name="key5" value="value5" />
</form>
Could the form data set be
[ (
"key1"
,"value1"
), ("key2"
,"value2"
), ("key3"
,"value3"
), ("submit"
,"Submit"
), ("key5"
,"value5"
) ]
(I.e. a depth-first search of the DOM); or
[ (
"key1"
,"value1"
), ("key5"
,"value5"
), ("key3"
,"value3"
), ("submit"
,"Submit"
), ("key2"
,"value2"
) ]
(A breadth-first search); or even a nondeterministic order resulting from iterating the control-name/current-value pairs in a randomized hashtable?
Testing this form with IE 9 and Firefox 9.0.1, it seems that both use the depth-first search order. Perhaps other browsers are different. The question is whether this order is prescribed somewhere.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您继续查看 HTML 规范的 17.13.4 部分,它声明默认内容类型是
application/x-www-form-urlencoded
。该内容类型的部分说:这表明深度优先遍历并且似乎与您的浏览器测试一致。
If you continue to section 17.13.4 of the HTML spec, it states that the default content type is
application/x-www-form-urlencoded
. The section for that content type says:This would suggest a depth-first traversal and would seem to agree with your browser tests.