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

标签 html forms http-get

考虑这种形式:

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

当提交这个GET表单时,参数ab正在消失。
有什么原因吗?
有没有办法避免这种行为?

最佳答案

这不就是隐藏参数的开始……吗?

<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/

相关文章:

javascript - rails : two radio selects on same source list

javascript - 有没有办法合并获取参数? - HTML/Javascript

php - 如何在 PHP 中为多个 get 请求保持 mysql 连接打开?

http - 如何使用 Matlab 或 Octave 进行 HTTP GET 或 POST?

html - 防止 html 元素在分辨率太小时被挤压

javascript - 从canvas html5存储大尺寸图像?

javascript - Popover 没有锚定到触发元素

html - 如何在不支付域名和主机费用的情况下学习制作网站(仅用于练习)?

forms - 在主窗体之前创建辅助窗体,同时保持 FormMain 作为主窗体?

mysql - 如何在 Coldfusion 中显示由 ID 分隔的数据库项目?