gpt4 book ai didi

javascript - Ajax发帖但对象错误

转载 作者:行者123 更新时间:2023-11-28 04:52:20 24 4
gpt4 key购买 nike

我面临发帖问题。当我使用按钮增加总值(value)时,会显示值(value),但是当我单击请求按钮时,所有发布都会更新,但余额不会更新。我检查数据库,插入“您已转移$[object Object]帐户余额”。请帮助我解决问题并帮助我完善。

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

关于javascript - Ajax发帖但对象错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42807605/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com