繁体   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