HTML:
<table id="invoice">
....
</table>
jQuery:
$.ajax({
url: "<?php echo base_url(); ?>reports/fetch_invoice/",
dataType: 'json',
type: 'post',
data: {
"from_date": from_date,
"to_date": to_date
},
success: function(data) {
for (i = 0; i < data.invoice.length; i++) {
var invoice = data.invoice[i]['invoice_id'];
var tr = '';
tr += '<tr><td>' + data.invoice[i]['emp_id'] +
'</td><td>' + data.invoice[i]['invoice_id'] +
'</td><td>' + data.invoice[i]['service'] +
'</td>';
$('#invoice').append(tr);
$.ajax({
url: "<?php echo base_url(); ?>reports/fetch_invoice_product/",
dataType: 'json',
type: 'post',
data: {
"invoice": invoice
},
success: function(data) {
var total = 0;
for (i = 0; i < data.product.length; i++) {
var tr = '';
total += parseInt(data.product[i]['total']);
}
tr += '<td>' + total +
'</td></tr>';
$('#invoice').append(tr);
}
});
}
}
});
第一个ajax方法将1行中的3列追加到表中,第二个ajax方法1row将显示为1行将成为表中第1行的第4列。 / p>