在页面加载时,我使用json结果填写表格。下面是我的所有代码表完全填满但是虽然我在FillGridView之后可以使用CalculatingOtherDetails它在控制器中使用空Amount()它不包含任何值。通过在控制台中放置中断,我发现当调用函数CalculatingOtherDetails()时,表没有填写。当我在CalculatingOtherDetails()之前调用FillGridView()函数时,它应该如何获得gridview值,但它不是
$(document).ready(function () {
FillGridView();
CalculatingOtherDetails();
}
});
function FillGridView() {
$.ajax({
url: "@Url.Action("PopulateGridView", "ConsolidatedMedicineBill")",
dataType: "json",
data: { patient_no: document.getElementById("IPDNo").value},
success: function (result) {
$.each(result, function (index, item) {
$('#MedicineDetails tr').last().after('<tr>' +
'<td class="column"></td>' +
'<td class="column" nowrap data-label="Medicine Name">' + item.medicine_name +
'</td><td class="column" nowrap data-label="Batch No">' + item.batch_no +
'</td><td class="column" nowrap data-label="Expiry Dt">' + item.expiry_date +
'</td><td class="column" nowrap data-label="Rate">' + item.rate +
'</td><td class="column" nowrap data-label="Qty">' + item.qty +
'</td><td class="column" nowrap data-label="Free Qty">' + item.free_qty +
'</td><td class="column" nowrap data-label="UOM">' + item.unit +
'</td><td class="column" nowrap data-label="Amount">' + item.amount +
'</td></tr>');
});
//Your success message
},
error: function (result) {
//alert("Error" + result);
//Your error message
}
});
CalculatingOtherDetails();
}
function CalculatingOtherDetails() {
var Amount = new Array();
$("table#MedicineDetails tr").each(function (row, tr) {
Amount[row] = $(tr).find('td:eq(8)').text();
});
Amount.shift();
console.log(Amount);
$.ajax({
url: "@Url.Action("CalculateAmountItem", "ConsolidatedMedicineBill")",
contentType: 'application/json; charset=utf-8',
type: 'POST',
cache: false,
data: JSON.stringify({ patient_no: document.getElementById("IPDNo").value, Amount: Amount }),
success: function (result) {
$.each(result, function (index, item) {
$('#ItemTotal').val(item.item_total);
$('#AddLess').val(item.add_less);
$('#SponsorAmt').val(item.sponsor_amount);
$('#Total').val(item.total);
$('#DepositAmt').val(item.deposit_amt);
$('#PaidAmt').val(item.paid_amt);
});
//Your success message
},
error: function (result) {
//alert("Error" + result);
//Your error message
}
});
}