表单操作 url 可以包含查询字符串值吗?

发布于 2024-09-17 19:39:26 字数 28 浏览 1 评论 0原文

表单操作 url 可以包含查询字符串值吗?

can a forms action url contain querystring values?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

强者自强 2024-09-24 19:39:26

是的,

可以。

但是

,当 method="get" 时,查询字符串将被删除并替换为表单输入名称/值(因为表单控件是构建 GET 查询字符串的控件) 。

<form method="get" action="?param=foo">
    <input type="hidden" name="param" value="bar" />
</form>

将提交param=bar

要保留该值,您应该在form 上指定method="post"

<form method="post" action="?param=foo">
    <input type="hidden" name="otherparam" value="bar" />
</form>

将提交 param=foo&otherparam=bar

<form method="post" action="?param=foo">
    <input type="hidden" name="param" value="bar" />
</form>

将提交 param=foo¶m=bar (因此,根据您处理请求的方式,您可以获得一个数组值或意想不到的结果)。

Yes

it can.

But

when method="get" then the querystring will be stripped out and replaced by the form input names/values (since the form controls are those that build the GET querystring).

<form method="get" action="?param=foo">
    <input type="hidden" name="param" value="bar" />
</form>

will submit param=bar

To keep the value you should specify method="post" on the form.

<form method="post" action="?param=foo">
    <input type="hidden" name="otherparam" value="bar" />
</form>

will submit param=foo&otherparam=bar

<form method="post" action="?param=foo">
    <input type="hidden" name="param" value="bar" />
</form>

will submit param=foo¶m=bar (so, depending on how you process the request, you could get either an array value or unexpected results).

债姬 2024-09-24 19:39:26

是的,可以。

(按键)

Yes, it can.

(Keystrokes)

ペ泪落弦音 2024-09-24 19:39:26

我刚刚使用简化的测试用例进行了检查:

  • Form.htm,其中包含一个带有 actiondefault.aspx?query=1 和一个提交按钮的表单。
  • default.aspx 中包含 Page_Load 中的代码,用于写出 Request.QueryString["query"]

单击该按钮时得到的结果是一个页面,内容如下:

1

所以,答案是肯定的。

I've just checked using a reduced test case:

  • Form.htm that contains a form with an action of default.aspx?query=1 and a submit button.
  • default.aspx that contains code in Page_Load to write out Request.QueryString["query"]

The result I got when clicking on the button was a page that read:

1

So, the answer is yes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文