如何从我的 URL 重定向中删除查询字符串
How do I remove the query-string from my URL redirect
所以我在下面制作了这个脚本,以便有人可以输入订单 ID,它会重定向到以下 http://domain.tld/order/254441。
但它在 URL 末尾给了我一个查询字符串 ?webid=254441。我该如何删除它?
function urlRedirect(){
var action_src = "/orders/" + document.getElementsByName("webid")[0].value;
var form_url = document.getElementById('form_url');
form_url.action = action_src ;
}
<p>Search by ID</p>
<form id="form_url" onsubmit="urlRedirect()"><input name="webid" type="text" /> <input type="submit" value="Search" /></form>
如果有人对改进代码提出建议,那就太好了! :)
谢谢。
将表单的 method
更改为 "POST"
。
<form id="form_url" onsubmit="urlRedirect()" method="POST">
HTTP POST 请求在消息正文中从客户端(浏览器)向服务器提供附加数据。相反,GET 请求在 URL 中包含所有必需的数据。当方法为 GET 时,所有表单数据都被编码到 URL 中,作为查询字符串参数附加到操作 URL 中。使用 POST,表单数据出现在 HTTP 请求的消息正文中。
所以我在下面制作了这个脚本,以便有人可以输入订单 ID,它会重定向到以下 http://domain.tld/order/254441。
但它在 URL 末尾给了我一个查询字符串 ?webid=254441。我该如何删除它?
function urlRedirect(){
var action_src = "/orders/" + document.getElementsByName("webid")[0].value;
var form_url = document.getElementById('form_url');
form_url.action = action_src ;
}
<p>Search by ID</p>
<form id="form_url" onsubmit="urlRedirect()"><input name="webid" type="text" /> <input type="submit" value="Search" /></form>
如果有人对改进代码提出建议,那就太好了! :)
谢谢。
将表单的 method
更改为 "POST"
。
<form id="form_url" onsubmit="urlRedirect()" method="POST">
HTTP POST 请求在消息正文中从客户端(浏览器)向服务器提供附加数据。相反,GET 请求在 URL 中包含所有必需的数据。当方法为 GET 时,所有表单数据都被编码到 URL 中,作为查询字符串参数附加到操作 URL 中。使用 POST,表单数据出现在 HTTP 请求的消息正文中。