我使用action="/sact/${searchp}/"
的post GET请求来提交用户搜索查询。
var searchp = search.querySelector("input.search-input").value;
// returns the normal value
document.body.innerHTML += `<form id="jsForm" action="/sact/${search}/" method="GET"><input type="hidden" name="a" value="a"></form>`;
document.getElementById("jsForm").submit();
重定向到这里:
router.get('/sact/:where', async (req, res, next) => {
res.render('search');
});
我不明白为什么/?每次提交时,a=a都会被添加到URL的后面。我该如何去除它?
当您使用method="GET"
时,document.getElementById("jsForm").submit();
将在URL上发送表单作为查询参数
a=a
来自这个字段<input type="hidden" name="a" value="a">
隐藏在HTML上,但仍然会在URL上发送
如果你想"隐藏"你可以使用method="POST"
将不可见的URL