0
我有一个按钮用于增加数量AJAX不加载内容
<input name="quantity-"'.$item_id.'" " id="quantity-'.$item_id.' " type="text" value="' . $quantity . '" />
$increase = '1';
<input name="increase-' . $item_id . '" id="increase-' . $item_id . '" type="button" value="+" onClick="cart_change_quantity('.$item_id .','.$quantity.','.$increase.')" />
功能:
function cart_change_quantity(item_id, quantity, mod) {
$.ajax({
url: 'functions/product-change-quantity.php',
type: 'GET',
data: {
item_id: item_id,
quantity: quantity,
mod: mod
},
success: function(response) {
if (response.search('success') != -1) {
var felbontva = response.split('__'),
new_quantity = felbontva[1];
$('#quantity-' + item_id).val(new_quantity);
}
else {
alert('An error occured while trying to update your order.');
}
}
});
}
和产品变化quantity.php:
$item_id = $_GET["item_id"];
$quantity = $_GET["quantity"];
$mod= $_GET["mod"];
if ($mod == '1') { $new_quantity = (int)$quantity + 1; }
echo 'success__' . $new_quantity;
它只是没有做任何物品ING。我想,以增加产品的数量与该按钮,后来我想这样做的背景更多的事情而无需刷新页面所以这就是为什么我的ajax选用 谢谢!
你应该张贴更多的HTML/PHP的组合,因为它是相当不可读的。 – Ulflander
你最喜欢的开发者控制台说什么?请求是否经过?什么是变数? – soulseekah
您能告诉我们脚本功能/ product-change-quantity.php的内容吗? – Stegrex