簡體   English   中英

Ajax發布但對象錯誤

[英]Ajax posting but object error

我正在發布問題。 當我使用按鈕增加總值時,則顯示值,但是當我單擊請求按鈕時,所有發布都會更新,但余額不會更新。 我檢查數據庫插入“你有轉移$ [對象對象]帳戶余額”。 請幫助解決問題並幫助我完善。

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

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

記住.text(something)設置值

.text()獲取值

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM