亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

表單提交到 python 代碼后刷新 HTML 頁面

表單提交到 python 代碼后刷新 HTML 頁面

莫回無 2023-10-20 16:30:29
我有一個 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 手動執行此操作
查看完整描述

1 回答

?
婷婷同學_

TA貢獻1844條經驗 獲得超8個贊

更改按鈕:

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

到:

<button onclick="window.setTimeout(function () {  window.location.reload();}, 10000)">download</button>

為我解決了。我刪除了

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

因為我需要在表單提交后刷新頁面


查看完整回答
反對 回復 2023-10-20
  • 1 回答
  • 0 關注
  • 134 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號