HTML表单提交时将标志添加到URL中

huangapple go评论81阅读模式
英文:

HTML form submit adding flag into URL

问题

I have a simple html form. When the form is submitted, the page is refreshed and the input is appended to the URL.

For example, the original URL is:

file:///Users/Download/dd.html

When the form is submitted, the URL becomes:

file:///Users/Download/dd.html?q=ccc

I want to add a flag to let the backend know where the request is from. Is it possible to add a flag into the header?

If not, I want to add &global to the end of the URL, so the URL becomes file:///Users/Download/dd.html?q=ccc&global. I tried to set the value of the input, but it will change what is displayed on the page.

I am wondering if it is possible to add a flag to the header, so my backend Java code can handle it. Or, add the flag to the end of the URL.

Thanks a lot!

英文:

I have a simple html form. When the form is submitted, the page is refreshed and the input is appended to the url.

<form>
     <input name="q" type="text" />
</form>

For example, the original URL is:

file:///Users/Download/dd.html

When the form is submitted, the URL becomes

file:///Users/Download/dd.html?q=ccc

I want to add a flag to let the backend knows where the request is from. Is it possible to add a flag into the header?

If not, I want to add &global to the end of the URL, so the url becomes file:///Users/Download/dd.html?q=ccc&global I tried to set the value of the input, but it will change what displayed in the page.

I am wondering if it is possible to add a flag into header, so my backend java code can handle it. Or, add the flag to the end of the URL.

Thanks a lot!

答案1

得分: 2

你不能通过表单添加标题,但你可以使用隐藏输入字段向表单添加其他参数。

<input type="hidden" name="global" value="" />

如果你真的想要添加标题,你将需要使用 JavaScript 和 Ajax。

请记住,一旦你在 URL 中使用参数,用户可以刷新页面或手动添加参数,这可能不是你预期的结果。

英文:

You cant add headers with a form but you can add other params to the form with a hidden input

&lt;input type=&quot;hidden&quot; name=&quot;global&quot; value=&quot;&quot; /&gt;

If you really want to add headers you will have to use javascript and ajax.

Keep in mind that once you use params in the url a user can either refresh the page or manually add the params which may not be what you expected.

huangapple
  • 本文由 发表于 2020年1月4日 00:45:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/59582232.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定