When submitting a GET form, the query string is removed from the action URL(提交 GET 表单时,查询字符串会从操作 URL 中删除)
问题描述
考虑这种形式:
<form action="http://www.blabla.com?a=1&b=2" method="GET">
<input type="hidden" name="c" value="3" />
</form>
当提交这个GET
表单时,参数a
和b
正在消失.
有什么原因吗?
有没有办法避免这种行为?
When submitting this GET
form, the parameters a
and b
are disappearing.
Is there a reason for that?
Is there a way of avoiding this behaviour?
推荐答案
这不就是隐藏参数的开始吗...?
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";并且 action 是一个 HTTP URI,用户代理获取 action 的值,附加一个?"然后附加表单数据集,使用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.
也许可以对操作 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.
这篇关于提交 GET 表单时,查询字符串会从操作 URL 中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:提交 GET 表单时,查询字符串会从操作 URL 中删除
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01