php - 使用 jquery 自动重新加载/刷新 div 会影响页面样式
问题描述
我设置了我的索引页面,其中包含挂单、销售和已完成的订单。数据每分钟都会更改。所以我决定通过 jquery 刷新特定的 div,并通过动态更改数据获得成功。但是问题从我的风格开始。当 div 重新加载时,卡片的风格会分散注意力。我不知道为什么会这样.
<div class="row" >
<div class="col-xl-3 col-lg-3 col-md-6 col-sm-12 col-12" id="here">
<div class="row">
<div class="col-xl-12">
<div class="card border-3 border-top border-top-primary">
<div class="card-body">
<h5 class="text-muted">Total Sales</h5>
<div class="metric-value d-inline-block">
<h1 class="mb-1 text-center"><? if($total != '') { echo "Rs: ".$total; } else { echo "Rs: 0";} ?></h1>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xl-12">
<div class="card border-3 border-top border-top-primary">
<div class="card-body">
<h5 class="text-muted">Complted Order</h5>
<div class="metric-value d-inline-block">
<h1 class="mb-1 text-center"><?= $complte." Nos"; ?></h1>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xl-12">
<div class="card border-3 border-top border-top-primary">
<div class="card-body">
<h5 class="text-muted">Pending Order</h5>
<div class="metric-value d-inline-block">
<h1 class="mb-1 text-center"><?= $pending." Nos"; ?></h1>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-xl-9 col-lg-12 col-md-6 col-sm-12 col-12">
<?
$orderquery = mysqli_query($conn,"SELECT * FROM ordermaster o LEFT JOIN customer c ON o.custid = c.custid WHERE o.status = 'p' AND orderdt = CURRENT_DATE() ");
?>
<div class="card">
<h5 class="card-header">Recent Orders</h5>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table">
<thead class="bg-light">
<tr class="border-0">
<th class="border-0">#</th>
<th class="border-0">Name</th>
<th class="border-0">Phone</th>
<th class="border-0">Address</th>
<th class="border-0">Pincode</th>
<th class="border-0">City</th>
<th class="border-0">Order Time</th>
<th class="border-0">Amount</th>
<th class="border-0">View</th>
</tr>
</thead>
<tbody>
<?
$count = 1;
while($res = mysqli_fetch_array($orderquery))
{
?>
<tr>
<td><?= $count; ?></td>
<td><?= $res['name']; ?> </td>
<td><?= $res['phone']; ?> </td>
<td><?= $res['addr1']."/".$res['addr2']; ?> </td>
<td><?= $res['pincode']; ?> </td>
<td><?= $res['city']; ?> </td>
<td><?= $res['orderdtm']; ?> </td>
<td><?= $res['net']; ?> </td>
<td><button class="btn btn-sm btn-outline-primary" title="View Product" onclick="del('<? echo $res['orderid'];?>')" value="id" data-toggle="modal" data-target="#delete" data-backdrop="static" data-keyboard="false"><i class="fas fa-eye"></i></button></td>
</tr>
<?
$count++;
}
?>
<tr>
<td colspan="9"><a href="#" class="btn btn-outline-light float-right">View Details</a></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
我重新加载 div 的 jquery 编码是
$(document).ready(function(){
setInterval(function(){
$("#here").load(window.location.href + " #here" );
}, 3000);
});
解决方案
要停止循环,您可以使用 clearInterval() Jquery 替换为
$(document).ready(function(){
window.setInterval(function(){
$("#here").load(window.location.href + " #here");
}, 3000);
clearInterval()
});
推荐阅读
- lua - 在 Lua 中更改表中的值
- java - 如何让 Swagger 在生成的 HTML(在 Swagger UI 页面中)中添加新行?
- delay - android coroutines delay() 有时延迟比指定的长
- php - 如何使用 PHP 和 google Drive API 创建文件夹,并立即更改共享权限?
- python - 在 SciPy 中生成 B-Spline 基,如 R 中的 bs()
- javascript - 为什么当我在 React 中将文本写入输入标签时我的文本没有改变
- python - Python:使用while循环为用户输入制作方法?
- python - 当我尝试在管理员中显示上传的文件时出现 DJANGO 消息错误,在更改页面中
- r - 将列值定义为反应性闪亮图的输入
- sql - 如何在SQL中设置参数以显示一段时间内的数据?