我有一個PHP-AJAX腳本從表中刪除現有財務行。 PHP腳本工作正常,行被刪除。但問題出在AJAX
的success
函數裏面。首先讓我告訴你表:無法使用AJAX和PHP更新表TD中的值返回JSON數組
忘記刪除付款按鈕,集中刪除項目。點擊它時,我想刪除已付款的所有項目,並且一切正常,直到我需要更新Total
,Still to Pay
和Total Paid
。
Total
單元格已正確更新,但是當我無法更新其他單元格時。我會在他們看到NaN $
。
這裏是腳本:
var pay_total = parseInt(pay_total) + parseInt(row.payment);
,以避免內部function(key, row) {...}
可變pay_total
重複聲明:
success:function(resp)
{
var pay_total = 0;
row.fadeOut(700);
//updating the total TD:
var totalVal = parseInt($("#final_cash").text());
var NewTotal = totalVal - parseInt(proj_cost);
$("#final_cash").text(NewTotal +' $');
//$.each because I have multiple rows returned from PHP
//and each row represent a payment in a different date.
$.each(resp, function(key, row)
{
$("#"+row.debt_id).fadeOut(600);
//Updating the still to pay TD:
var pay_total = parseInt(pay_total) + parseInt(row.payment);
console.log(pay_total);//The result is NaN
var still_cash_t = parseInt($("#still_cash").text());
var sct = pay_total + still_cash_t;
$("#still_cash").text(sct + ' $');
//Updating the Total Paid TD:
var paid_cash_t = parseInt($("#paid_cash").text());
var pct = paid_cash_t - pay_total;
$("#paid_cash").text(pct +' $');
});
},
OT:您在一個函數中使用了3種不同的命名約定。 –