考虑这种形式:
<form action="http://www.blabla.com?a=1&b=2" method="GET">
<input type="hidden" name="c" value="3" />
</form>
当提交这个GET
表单时,参数a
和b
正在消失。
有什么原因吗?
有没有办法避免这种行为?
最佳答案
这不就是隐藏参数的开始……吗?
<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 中保留任何现有的查询字符串。
如规范(RFC1866,第 46 页;HTML 4.x 第 17.13.3 节)所述:
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.
也许可以对操作 URL 进行百分比编码以嵌入问号和参数,然后祈祷所有浏览器都会保留该 URL(并验证服务器是否也能理解它)。但我永远不会依赖它。
顺便说一句:对于非隐藏的表单字段,它并没有什么不同。但是对于 POST,操作 URL 可以包含一个查询字符串。
关于html - 提交 GET 表单时,查询字符串会从操作 URL 中删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1116019/