[英]Append Problem with JSON data to HTML Table
I have problem after showing json data to html table.将 json 数据显示到 html 表后出现问题。
The problems;问题;
Here's my code:这是我的代码:
<table class="table" id="history_maintenance">
<thead>
<th>Date In</th>
<th>SPK No</th>
<th>Purchase No</th>
<th>Maintenance Notes</th>
</thead>
<tbody></tbody>
</table>
<script>
$('#product_id').on('change', function() {
let customer_name = document.getElementById("customer_name").value;
let phone = document.getElementById("phone").value;
let car_plate_no = document.getElementById("car_plate_no").value;
let car_type = document.getElementById("car_type").value;
let product_id = document.getElementById("product_id").value;
$.ajax({
type: "POST",
url: "<?php echo base_url('spk/get_customer_transaction_history') ?>",
dataType: "json",
cache: false,
data: {
customer_name: customer_name,
phone: phone,
car_plate_no: car_plate_no,
car_type: car_type,
product_id: product_id,
},
success: function(dataHistory) {
let transactionHistory = '';
for (i = 0; i < dataHistory.length; i++) {
transactionHistory += '<tr>';
transactionHistory += '<td>' + dataHistory[i].date_in + '</td>';
transactionHistory += '<td>' + dataHistory[i].spk_no + '</td>';
transactionHistory += '<td>' + dataHistory[i].purchase_no + '</td>';
transactionHistory += '<td>' + dataHistory[i].spk_maintenance_notes + '</td>';
transactionHistory += '</tr>';
}
$('#history_maintenance tbody').append(transactionHistory);
}
});
return false;
});
</script>
thanks @EL_vanja for the tips感谢@EL_vanja 的提示
i add this:我补充说:
$('#history_maintenance tbody').html('');
before:前:
let transactionHistory = '';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.