2016-05-12 27 views
0

我有一個PHP-AJAX腳本從表中刪除現有財務行。 PHP腳本工作正常,行被刪除。但問題出在AJAXsuccess函數裏面。首先讓我告訴你表:無法使用AJAX和PHP更新表TD中的值返回JSON數組

enter image description here

忘記刪除付款按鈕,集中刪除項目。點擊它時,我想刪除已付款的所有項目,並且一切正常,直到我需要更新TotalStill to PayTotal Paid

Total單元格已正確更新,但是當我無法更新其他單元格時。我會在他們看到NaN $

enter image description here

這裏是腳本:

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 +' $'); 
     }); 
    }, 
+0

OT:您在一個函數中使用了3種不同的命名約定。 –

回答

2

在刪除var

1

看來你加入或可能減去到JSON值,這就是爲什麼它顯示南,它似乎行爲像字符串值,如果你把它轉換成數字然後這個問題可以解決。在添加/減去某個值之前將其轉換爲數字