javascript - 使用 post 方法点击搜索按钮后 URL 不会改变

标签 javascript python html flask jinja2

我访问了一个包含 URL 参数的页面。 例如http://127.0.0.1:5000/?A=ABC123&B=44444&C=hello

当我单击搜索按钮时,使用一些搜索字符串,使用 form method = post,它会进行搜索,但具有相同的 URL,其中包含上次运行的值。 它显示搜索结果,但参数仍然具有上次运行的值 - http://127.0.0.1:5000/?A=ABC123&B=44444&C=hello

我想删除 url 参数。经过我的搜索,URL应该是http://127.0.0.1:5000/

<form method="POST">
   <input type="text" name="search">
   <button type="submit"><i class="fa fa-search"></i></button>
</form>

我希望搜索按钮应该清除现有的 URL 参数。

最佳答案

据我了解,您可以重定向到请求路径,这将清除网址参数:

@app.route("/search", methods=["POST"])
def search():
    ... get results ...
    redirect(request.path)

关于javascript - 使用 post 方法点击搜索按钮后 URL 不会改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57363280/

相关文章:

javascript - jquery this 与 $(this) 甚至 $this

python - 在 fastapi python 中使 Depends 可选

html - 100% 分区高度

javascript - 如何使用 Selenium Python 在 WordPress 帖子中上传文件?

javascript - 在 React 中将组件定义为对象

python - Python 中的 >> 和 << 运算符是什么?

python - 如何从 python 数据框中检索和存储多个值?

javascript - 如何从系统获取图像以加载到html5的canvas中

html - 如何调整 HTML/CSS 页面的大小,以便在调整窗口大小时 itens 不会移动

javascript - 如果使用 jQuery 在母版页内呈现控件,如何获取控件 id?