我開發了一個購物網站,我正在使用ajax處理添加到購物車並從購物車中刪除。添加到購物車工作正常,但從購物車中刪除正在創建一個奇怪的問題。我能夠從中刪除一條記錄,如果我想刪除更多,我需要手動刷新頁面,然後我將能夠刪除多一個。這很奇怪,我無法找到錯誤的地方。無法刪除多個購物車項目
這裏是代碼:
jQuery('.remove').click(function(data) {
var pi = jQuery(this).attr('name');
var y = jQuery(this).attr('name');
$.ajax({
url: "delcart.php?pid="+pi+"&data="+y,
type: 'GET',
success: function(s){
var $container = $("#content");
// $container.refresh("index.php");
$("#content").load(location.href + " #content");
$("#success2").show().fadeOut(6000);
},
error: function(e){
alert('Error Processing your Request!!');
}
});
});
HTML按鈕。
<button name="<?php echo $ca['ID'];?>" class="remove close_product color_dark tr_hover">x</button>
此按鈕進入while循環,每次名稱屬性由數據庫購物車表的唯一ID組成。
這裏是delcart.php:
<?php
include_once "config.php";
$id = $_GET['pid'];
$ip = $_SERVER['REMOTE_ADDR'];
$de = mysqli_query($con,"DELETE from cart where ID='{$id}' and ip='{$ip}'");
?>
誰能請圖什麼我錯過了或者錯誤的。這將是一個巨大的幫助。提前致謝。
在您的瀏覽器devTools上查找錯誤,請按F12 –
ajax調用可能會被緩存。你應該使用帖子並在你的帖子數據中附加一個隨機數字。 '&rand =(js創建的隨機數)'這會阻止呼叫被緩存。 – VIDesignz