我有一個顯示視頻游戲中物品價格的網站。目前,我有一個“自動刷新”腳本,每 5 秒刷新一次頁面,但這有點煩人,因為每次您搜索產品時,它都會刪除您的搜索,因為頁面會刷新。我想在不為用戶刷新頁面的情況下更新表中的數字。我在 javascript 中閱讀了一些關于“更新 DOM”的內容,但沒有理解。這是我網站的鏈接:http: //xeltool.com/這是我的 python 代碼:@app.route('/bprices', methods=['GET'])def bPrices(): f = requests.get( 'https://api.hypixel.net/skyblock/bazaar?key=[cannot show]').json() products = [ { "id": product["product_id"], "sell_price": product["sell_summary"][:1], "buy_price": product["buy_summary"][:1], "sell_volume": product["quick_status"]["sellVolume"], "buy_volume": product["quick_status"]["buyVolume"], } for product in f["products"].values() ] return render_template("bprices.html", products=products)
2 回答

撒科打諢
TA貢獻1934條經驗 獲得超2個贊
您有 3 個選擇:
SSE - https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events
Websocket - https://developer.mozilla.org/en-US/docs/Glossary/WebSockets
我認為在您的情況下最好的選擇是 SSE,因為服務器知道價格已更改,因此可以將其推送給客戶。
添加回答
舉報
0/150
提交
取消