英文:
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
<input type="hidden" name="global" value="" />
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论