简体   繁体   English

Ajax发布但对象错误

[英]Ajax posting but object error

I am faccing posting issue. 我正在发布问题。 When I increase the total value with button then value are showing but when I click the request button then all posting are updated but balance do not update. 当我使用按钮增加总值时,则显示值,但是当我单击请求按钮时,所有发布都会更新,但余额不会更新。 And I check the database there insert into "You have transfer $[object Object] Account Balance". 我检查数据库插入“你有转移$ [对象对象]帐户余额”。 Please help what is the problem and help me for perfection. 请帮助解决问题并帮助我完善。

 $(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> 

You are sending the whole element in the data. 您正在发送数据中的整个元素。 I beleive you need to send the data only. 我相信你只需要发送数据。 What you are doing in line var af = $('.total').text(theTotal.toFixed(2)); 你在做什么行var af = $('。total')。text(theTotal.toFixed(2)); is you are setting the value for that element and assigning the element to a variable. 您是设置该元素的值并将该元素分配给变量。

Remember .text(something) sets the value 记住.text(something)设置值

.text() gets the value .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