且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

提交 GET 表单时,查询字符串将从操作 URL 中删除

更新时间:2023-02-23 10:53:36

隐藏参数不就是用来开始的吗...?

Isn't that what hidden parameters are for to start with...?

<form action="http://www.example.com" method="GET">
  <input type="hidden" name="a" value="1" /> 
  <input type="hidden" name="b" value="2" /> 
  <input type="hidden" name="c" value="3" /> 
  <input type="submit" /> 
</form>

我不会指望任何浏览器在操作 URL 中保留任何现有的查询字符串.

I wouldn't count on any browser retaining any existing query string in the action URL.

作为规范(RFC1866,第 46 页;HTML 4.x 部分 17.13.3) 状态:

As the specifications (RFC1866, page 46; HTML 4.x section 17.13.3) state:

如果方法是get"并且动作是一个 HTTP URI,用户代理获取动作的值,附加一个?"然后附加表单数据集,使用application/x-www-form-urlencoded"编码.内容类型.

If the method is "get" and the action is an HTTP URI, the user agent takes the value of action, appends a `?' to it, then appends the form data set, encoded using the "application/x-www-form-urlencoded" content type.

也许可以对 action-URL 进行百分比编码以嵌入问号和参数,然后交叉手指希望所有浏览器都保留该 URL(并验证服务器是否也理解它).但我永远不会依赖它.

Maybe one could percent-encode the action-URL to embed the question mark and the parameters, and then cross one's fingers to hope all browsers would leave that URL as it (and validate that the server understands it too). But I'd never rely on that.

顺便说一句:对于非隐藏的表单字段,这并没有什么不同.对于 POST,动作 URL 可以包含一个查询字符串.

By the way: it's not different for non-hidden form fields. For POST the action URL could hold a query string though.