表单提交到 python 代码后刷新 HTML 页面

我有一个 HTML 代码,其中有一个“下载”按钮,可以通过 GET 将文件下载到 python 代码,问题是该页面的刷新率为 5 秒,并且运行良好,但是一旦我单击下载按钮文件下载完毕后,页面停止刷新。


我能做什么来修复它?


HTML:


<html>

<meta http-equiv="refresh" content="5">

<style>

mark {

       background-color: grey;

        color: white;

}

</style>

<title>{{client}}</title>

        

        <form target="_parent" method="get" action="download_file" style="display: inline;">

        <h4><mark>{{client}}</mark></h4>

                        <br>

                        <br>

                        <button  onclick="openNav()">download</button>

                    <input type=hidden name="client" value="{{client}}">

                    <input type=hidden name="reason" value="{{reason}}">

        </form>

    </body>

    <script>function openNav() {

      document.getElementById("myNav").style.width = "100%";

    }

    </script>

    </html>

Python:


@app.route("/download_file", methods=["GET"])

def download_file():

#a lot of code to get the file

    response = flask.Response(output, mimetype="zip", headers={"Content-disposition":"attachment; filename="+  randomName + ".zip"})

    return response

已尝试添加onclick按钮,但"window.location.reload();"不执行任何操作,它会等到文件下载完成并且页面失去刷新选项,直到我在页面上使用 F5 手动执行此操作


莫回无
浏览 112回答 1
1回答

婷婷同学_

更改按钮:<button&nbsp;&nbsp;onclick="openNav()">download</button>到:<button&nbsp;onclick="window.setTimeout(function&nbsp;()&nbsp;{&nbsp;&nbsp;window.location.reload();},&nbsp;10000)">download</button>为我解决了。我删除了<meta&nbsp;http-equiv="refresh"&nbsp;content="5">因为我需要在表单提交后刷新页面
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript