【发布时间】:2020-06-02 15:41:43
【问题描述】:
所以我正在尝试更新产品的价格,而无需刷新。等它更新直播,但我不明白。看了一堆帖子,没搞明白。
这是我的python代码:
@app.route('/bprices', methods=['GET'])
def bPrices():
f = requests.get(
'https://api.hypixel.net/skyblock/bazaar?key=[can get you a key if needed]').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 jsonify(products=products)
这是我的 HTML + js:
<table
id="myTable"
class="table table-striped table-bordered table-sm table-dark sortable"
cellspacing="0"
>
<thead>
<tr>
<th aria-label="Product Name" data-balloon-pos="up">Product</th>
<th aria-label="Product's buy price" data-balloon-pos="up">
Buy Price
</th>
<th aria-label="Product's sell price" data-balloon-pos="up">
Sell Price
</th>
<th aria-label="Product's buy volume" data-balloon-pos="up">
Buy Volume
</th>
<th aria-label="Product's sell volume" data-balloon-pos="up">
Sell Volume
</th>
<th>
Margin
</th>
</tr>
</thead>
<tbody>
<tr>
<td id="price"></td>
</tr>
</tbody>
</table>
</div>
<script>
$SCRIPT_ROOT = {{ request.script_root | tojson | safe }};
(function () {
$.getJSON(
$SCRIPT_ROOT + "/_stuff", // Your AJAX route here
function (data) {
$("#price").text(data.products)
}
);
setTimeout(arguments.callee, 10000);
})();
</script>
目前,它只显示我想要访问的数据的 JSON 文件,很可能是因为“jsonify”。
【问题讨论】: