2017-03-15 48 views
1

我正在發佈發佈問題。當我用按鈕增加總價值時,值顯示,但當我點擊請求按鈕,然後所有發佈更新但餘額不更新。我檢查數據庫插入到「你有轉移$ [對象對象]帳戶餘額」。請幫助解決問題並幫助我達到完美。阿賈克斯發佈但對象錯誤

$(function(){ 
 
\t 
 
var theTotal = 10; 
 

 
$('.add').click(function(){ 
 
    theTotal = Number(theTotal) + Number($(this).val()); 
 
    $('.total').text(theTotal.toFixed(2)); 
 
}); 
 

 
$('.sub1').click(function(){ 
 
\t if(theTotal > 10) { 
 
     theTotal = Number(theTotal) - Number($(this).val()); 
 
\t }; 
 
    $('.total').text(theTotal.toFixed(2)); 
 
}); 
 

 
$('.sub2').click(function(){ 
 
\t if(theTotal > 10) { 
 
     theTotal = Number(theTotal) - Number($(this).val()); 
 
\t }; 
 
    $('.total').text(theTotal.toFixed(2)); 
 
}); 
 

 
$('.sub3').click(function(){ 
 
\t if(theTotal > 10) { 
 
     theTotal = Number(theTotal) - Number($(this).val()); 
 
\t }; 
 
    $('.total').text(theTotal.toFixed(2)); 
 
}); 
 

 

 
var af = $('.total').text(theTotal.toFixed(2)); 
 

 
\t 
 
\t $('#request').click(function(){ 
 
\t \t $.ajax({ 
 
\t \t \t type:'POST', 
 
\t \t \t url:window.location.protocol+'//'+window.location.host+'/?add=fund', 
 
\t \t \t data:'qun='+af, 
 
\t \t \t cache:false, 
 
\t \t \t beforeSend:function(){ 
 
\t \t \t \t $('html *').addClass('op-progress'); 
 
\t \t \t }, success:function(html){ 
 
\t \t \t \t $('html *').removeClass('op-progress'); 
 
\t \t \t \t document.location.href=_url+'/?add=fund'; 
 
\t \t \t } 
 
\t \t }); 
 
\t }); 
 
\t 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script> 
 
<table style="margin-bottom:15px;"> 
 
\t <tr> 
 
\t \t <td> 
 
\t \t \t <button class="sub3 p_btn" value="10"><<<</button> 
 
      <button class="sub2 p_btn" value="10"><<</button> 
 
\t \t \t <button class="sub1 p_btn" value="10"><</button> 
 
\t \t </td> 
 
\t \t \t \t \t \t 
 
\t \t <td> 
 
\t \t \t <span class="f_mb_dol">$</span> 
 
\t \t \t <span class="total f_mb_text"></span> 
 
\t \t \t <div class="f_mb_dol">usd</div> 
 
\t \t </td> 
 
\t \t \t \t \t \t 
 
\t \t <td> 
 
\t \t \t <button class="add p_btn" value="10">></button> 
 
      <button class="add p_btn" value="10">>></button> 
 
\t \t \t <button class="add p_btn" value="10">>>></button> 
 
\t \t </td> 
 
\t </tr> 
 
</table> 
 
\t \t \t \t 
 
<table> 
 
    <tr> 
 
\t <td><button id="request" class="btn_enable" style="cursor:pointer;"><span>Transfer balance</span></button></td> 
 
    </tr> 
 
</table>

+0

哪裏是PHP和MySQL的代碼? – hassan

回答

0

您發送整個單元中的數據。 我相信你只需要發送數據。你在做什麼var af = $('。total').text(theTotal.toFixed(2));您是在設置該元素的值並將該元素分配給一個變量。

記住的.text(東西)設定值

的.text()得到值

$(function(){ 
 
var af; 
 
var theTotal = 10; 
 

 
$('.add').click(function(){ 
 
    theTotal = Number(theTotal) + Number($(this).val()); 
 
    $('.total').text(theTotal.toFixed(2)); 
 
}); 
 

 
$('.sub1').click(function(){ 
 
\t if(theTotal > 10) { 
 
     theTotal = Number(theTotal) - Number($(this).val()); 
 
\t } 
 
    $('.total').text(theTotal.toFixed(2)); 
 
}); 
 

 
$('.sub2').click(function(){ 
 
\t if(theTotal > 10) { 
 
     theTotal = Number(theTotal) - Number($(this).val()); 
 
\t } 
 
    $('.total').text(theTotal.toFixed(2)); 
 
}); 
 

 
$('.sub3').click(function(){ 
 
\t if(theTotal > 10) { 
 
     theTotal = Number(theTotal) - Number($(this).val()); 
 
\t } 
 
    $('.total').text(theTotal.toFixed(2)); 
 
}); 
 

 

 
$('.total').text(theTotal.toFixed(2)); 
 
    \t $('#request').click(function(){ 
 
af = $('.total').text(); 
 
    console.log(af); 
 
\t \t $.ajax({ 
 
\t \t \t type:'POST', 
 
\t \t \t url:window.location.protocol+'//'+window.location.host+'/?add=fund', 
 
\t \t \t data:'qun='+af, 
 
\t \t \t cache:false, 
 
\t \t \t beforeSend:function(){ 
 
\t \t \t \t $('html *').addClass('op-progress'); 
 
\t \t \t }, success:function(html){ 
 
\t \t \t \t $('html *').removeClass('op-progress'); 
 
\t \t \t \t document.location.href=_url+'/?add=fund'; 
 
\t \t \t } 
 
\t \t }); 
 
\t }); 
 
\t 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script> 
 
<table style="margin-bottom:15px;"> 
 
\t <tr> 
 
\t \t <td> 
 
\t \t \t <button class="sub3 p_btn" value="10"><<<</button> 
 
      <button class="sub2 p_btn" value="10"><<</button> 
 
\t \t \t <button class="sub1 p_btn" value="10"><</button> 
 
\t \t </td> 
 
\t \t \t \t \t \t 
 
\t \t <td> 
 
\t \t \t <span class="f_mb_dol">$</span> 
 
\t \t \t <span class="total f_mb_text"></span> 
 
\t \t \t <div class="f_mb_dol">usd</div> 
 
\t \t </td> 
 
\t \t \t \t \t \t 
 
\t \t <td> 
 
\t \t \t <button class="add p_btn" value="10">></button> 
 
      <button class="add p_btn" value="10">>></button> 
 
\t \t \t <button class="add p_btn" value="10">>>></button> 
 
\t \t </td> 
 
\t </tr> 
 
</table> 
 
\t \t \t \t 
 
<table> 
 
    <tr> 
 
\t  <td><button id="request" class="btn_enable" style="cursor:pointer;"><span>Transfer balance</span></button></td> 
 
\t </tr> 
 
</table>

+0

OP爲什麼要「嘗試此代碼」?一個**好的答案**總是會解釋做了什麼以及爲什麼這樣做, 不僅適用於OP,而且適用於SO的未來訪問者,可能會發現此問題並正在閱讀您的答案。 – RiggsFolly

+0

是的先生編輯它先生@RiggsFolly – CaptainHere

+0

如果你以某種方式表明_你實際上已經改變了什麼_ – RiggsFolly