|
|
|
ต้องการให้ข้อมูลอัปเดตใน div โดยไม่ Refresh Page (F5) หลังจาก Ajax ส่งข้อมูลไปแก้ไขฐานข้อมูล |
|
|
|
|
|
|
|
เมื่อกดอัปเดตจาก Datatable โดยใช้ function Ej(id) ข้อมูลในตารางอัปเดต
แต่ใน div ที่แสดงไม่เปลี่ยน มีวิธีอย่างไรบ้างครับ
ไม่ต้องการให้หน้ามีการ Refresh (F5) ครับ
index.php
<div class="row">
<?php
//รับค่า year
$query_year = "SELECT `year` FROM `system` ";
$result_year = mysqli_query($con,$query_year);
if (false === $result_year) {
die(mysqli_error($con));
}
while ($row_year = mysqli_fetch_assoc($result_year)) {
$year_data = $row_year['year'];
break;
}
$check_sall = "SELECT `short_status` FROM request WHERE `year`= '$year_data'";
$result_sall = mysqli_query($con, $check_sall);
if (false === $result_sall) {
die(mysqli_error($con));
}
$num_sall = mysqli_num_rows($result_sall);
$check_s100 = "SELECT `short_status` FROM request WHERE `year`= '$year_data' AND `short_status` = '100%' ";
$result_s100 = mysqli_query($con, $check_s100);
if (false === $result_s100) {
die(mysqli_error($con));
}
$num_s100 = mysqli_num_rows($result_s100);
$check_s50 = "SELECT `short_status` FROM request WHERE `year`= '$year_data' AND `short_status` = '50%' ";
$result_s50 = mysqli_query($con, $check_s50);
if (false === $result_s50) {
die(mysqli_error($con));
}
$num_s50 = mysqli_num_rows($result_s50);
$check_s0 = "SELECT `short_status` FROM request WHERE `year`= '$year_data' AND `short_status` = '0%' ";
$result_s0 = mysqli_query($con, $check_s0);
if (false === $result_s0) {
die(mysqli_error($con));
}
$num_s0 = mysqli_num_rows($result_s0);
$check_ej = "SELECT `short_status` FROM request WHERE `year`= '$year_data' AND `short_status` = 'E' ";
$result_ej = mysqli_query($con, $check_ej);
if (false === $result_ej) {
die(mysqli_error($con));
}
$num_ej = mysqli_num_rows($result_ej);
if($num_sall == 0){
$num_s100_persen = '0%';
$num_s50_persen = '0%';
$num_s0_persen = '0%';
$num_ej_persen = '0%';
} else {
$num_s100_persen = $num_s100*100/$num_sall.'%';
$num_s50_persen = $num_s50*100/$num_sall.'%';
$num_s0_persen = $num_s0*100/$num_sall.'%';
$num_ej_persen = $num_ej*100/$num_sall.'%';
}
?>
<div class="col-xl-3 d-none d-xl-block">
<div class="card card-custom bg-light-info card-stretch gutter-b">
<!--begin::Body-->
<div class="card-body my-3" >
<a href="#" class="card-title font-weight-bolder text-info text-hover-state-dark font-size-h6 mb-4 d-block">ส่งคำร้องแล้ว</a>
<div class="font-weight-bold text-muted font-size-sm">
<span class="text-dark-75 font-size-h2 font-weight-bolder mr-2"><?=$num_s0_persen?></span>รวม <?=$num_s0?> คน</div>
<div class="progress progress-xs mt-7 bg-info-o-60">
<div class="progress-bar bg-info" role="progressbar" style="width: <?=$num_s0_persen?>;" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
<!--end:: Body-->
</div>
</div>
<div class="col-xl-3 d-none d-xl-block">
<div class="card card-custom bg-light-warning card-stretch gutter-b">
<!--begin::Body-->
<div class="card-body my-3" >
<a href="#" class="card-title font-weight-bolder text-warning text-hover-state-dark font-size-h6 mb-4 d-block">รับคำร้องแล้ว</a>
<div class="font-weight-bold text-muted font-size-sm">
<span class="text-dark-75 font-size-h2 font-weight-bolder mr-2"><?=$num_s50_persen?></span>รวม <?=$num_s50?> คน</div>
<div class="progress progress-xs mt-7 bg-warning-o-60">
<div class="progress-bar bg-warning" role="progressbar" style="width: <?=$num_s50_persen?>;" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
<!--end:: Body-->
</div>
</div>
<div class="col-xl-3 d-none d-xl-block">
<div class="card card-custom bg-light-success card-stretch gutter-b">
<!--begin::Body-->
<div class="card-body my-3" >
<a href="#" class="card-title font-weight-bolder text-success text-hover-state-dark font-size-h6 mb-4 d-block">ส่งคืนแล้ว</a>
<div class="font-weight-bold text-muted font-size-sm">
<span class="text-dark-75 font-size-h2 font-weight-bolder mr-2"><?=$num_s100_persen?></span>รวม <?=$num_s100?> คน</div>
<div class="progress progress-xs mt-7 bg-success-o-60">
<div class="progress-bar bg-success" role="progressbar" style="width: <?=$num_s100_persen?>;" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
<!--end:: Body-->
</div>
</div>
<div class="col-xl-3 d-none d-xl-block">
<div class="card card-custom bg-light-danger card-stretch gutter-b">
<!--begin::Body-->
<div class="card-body my-3" >
<a href="#" class="card-title font-weight-bolder text-danger text-hover-state-dark font-size-h6 mb-4 d-block">ปฎิเสธแล้ว</a>
<div class="font-weight-bold text-muted font-size-sm">
<span class="text-dark-75 font-size-h2 font-weight-bolder mr-2"><?=$num_ej_persen?></span>รวม <?=$num_ej?>คน</div>
<div class="progress progress-xs mt-7 bg-danger-o-60">
<div class="progress-bar bg-danger" role="progressbar" style="width: <?=$num_ej_persen?>;" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
<!--end:: Body-->
</div>
</div>
</div>
ajax.js
function Ej(id){
$.ajax({
url:'sql/admin/update_req.php',
method: 'POST',
data: {id:id,function:'Ej'},
success:function(data){
Swal.fire({
title: "สำเร็จ!",
text: "อัปเดตสถานะสำเร็จ [SUCCESS]",
icon: "success",
confirmButtonText: 'ตกลง',
confirmButtonColor: '#30d651'
}).then(function() {
$('#loadreq').DataTable().draw();
location.reload();
})
}
})
}
</script>
Tag : PHP, MySQL, CSS, HTML5, JavaScript
|
|
|
|
|
|
Date :
2021-09-06 22:44:45 |
By :
jgogo01 |
View :
778 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อธิบายให้เคลียร์ก่อน
Update ข้อมูลใน div
div=????
ก็มี div เยอะแยะ
|
|
|
|
|
Date :
2021-09-07 10:15:08 |
By :
oops |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|