gpt4 book ai didi

javascript - 更新产品数量而不进行回发

转载 作者:行者123 更新时间:2023-11-28 01:41:06 27 4
gpt4 key购买 nike

我正在做一个项目,但我陷入了一种情况。

当我添加到购物车时,我需要检查添加的数量以及产品,我使用 JQuery 函数来执行此操作。

虽然用户尚未结账,但我将 qtyproduct_id 存储在一个数据表中。如果用户删除产品,我也会更改数量。

但是当我在购物车中添加产品时,回发没有发生。因此,绑定(bind)到另一个数据表(使用数据库)的 Qty 不会更新其值。所以我很困惑该怎么办请帮我解决这个问题。

插入产品

function InsertProduct(product_id, qty, totalqty) {
if (qty == "Details") {
debugger;

if ($('#txtqty').val().trim() != "") {
if (!validateTextNumericInRange($('#txtqty').val())) {
alert("You have entered invalid product Quantity.");
return false;
}
}
} else {
qty = "1";
price_type = 'sale';
}

debugger;

var tempqty;
if (qty == "Details") {
tempqty = $('#lblcurrent_stock').text();
} else {
totalqty = parseInt(totalqty,10)

if (totalqty != 0) {
totalqty=totalqty-1;
tempqty=totalqty;
} else {
alert("Sorry We Are Running Of Stock For this Product. Will Soon Update the Stock");
return false;
}
}

$('#target').show();
$('#target').html('<img src="images/ajax-loader1.gif" style="margin-left: 50%;padding: 10px;"/>')
$.get("minicart.aspx?product_id="+product_id+"&qty="+qty+"&price="+pricetype_prescription+"&price_type="+price_type+"&tempqty="+tempqty+"#minicart", function( data ) {

var resourceContent = data;

data = $(data).find('div#minicart');
$('#target').html(data);

var mini = $(resourceContent).find('div#pnlminicart')

$('#smallcart').html(mini);
$('#target').delay(7000).slideUp('slow');

// can be a global variable too...
// process the content...
});
return false;
}

这里detail是另一个正常工作的页面。这是我无法更新totalqty 值。这里validateTextNumericInRange用于验证数量。

最佳答案

如果您在标签控件中显示信息,即使您在触发回发函数时使用 jQuery 更新数量,它也会从 View 状态中读取原始数量。我有同样的问题。我找到了一个解决方法: ASP.Net label value changed in JQuery but unchanged at postback

还将数量存储在不可见的文本框中,并在回发时从中读取值。

关于javascript - 更新产品数量而不进行回发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20916886/

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