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