public class OrderBookEntry {
private String price;
private String qty;
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getQty() {
return qty;
}
public void setQty(String qty) {
this.qty = qty;
}
}
如果数量从1更改为2,则自动刷新网页而不闪烁。我该怎么办?
我查看了不同的解决方案https://aiocollective.com/blog/ajax-auto-refresh-volume-ii/和此How can I refresh a page when a database is updated?,但这与我想要的不一样。第二页解决方案更相似,但这并不需要刷新页面的要求,它仅检查数据库号是否发生更改。
答案 0 :(得分:0)
php文件
$id=$_POST['id'];
if (is_numeric($id))
{
$counter = "SELECT count(*) as countnumber FROM onairsystem WHERE id={$id}";
$counterresult = $connection->query($counter);
$rows = $counterresult->fetch_array();
echo $number = $rows['countnumber'];
}
html文件
<input type="number" id="number" name="number">
<button onclick="getDate()">Get Data From Query</button>
<br>
<label class="data"></label>
<script>
function getDate()
{
var number = $('#number').val();
$.ajax({
type: "POST",
url: 'ajax.php?id='+number,
success: function(data)
{
$('.data').val(data);
}
});
}
</script>