Skip to content

Commit

Permalink
购物车删除全部优化 2020年7月9日16:20:30
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeratul-X committed Jul 9, 2020
1 parent dd6a62a commit 9381f54
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 12 deletions.
3 changes: 0 additions & 3 deletions src/js/detailInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ $('#addToCar').on('click', function () {
'username': chooseContent['username'],
},
success: (data) => {
console.log(data);
if (data.code == 1 || data.code==0) {
//说明当前用户的购物车没有商品信息
//直接将该商品insert into
Expand Down Expand Up @@ -190,7 +189,6 @@ $('#addToCar').on('click', function () {
function insertDataToDataBase(chooseContent) {
chooseContent['totalPrice'] = chooseContent['singlePrice'];
chooseContent['number'] = 1;
console.log(chooseContent);
$.ajax({
url:'../php/addToShopCarNoInfo.php',
type: 'post',
Expand All @@ -207,7 +205,6 @@ function insertDataToDataBase(chooseContent) {
'imgUrl': chooseContent['imgUrl']
},
success: (data)=>{
console.log(data);

}
});
Expand Down
2 changes: 0 additions & 2 deletions src/js/goodsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ for (var i = 0; i < urlArr.length; i++) {


$(window).load(function () {
console.log(typestr);
$.ajax({
url: '../php/goodsList.php',
dataType: 'json',
Expand All @@ -21,7 +20,6 @@ $(window).load(function () {
},
async: true,
success: (data) => {
console.log(data);
var num = Math.floor(data.length / 5);
var remianer = data.length % 5;
data['num'] = num;
Expand Down
1 change: 0 additions & 1 deletion src/js/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ $('#loginBtn').click(function () {
},
dataType: 'json',
success: (data) => {
console.log(data);
if (data.code == 0) {
window.location.href = '../pages/index.html';
}
Expand Down
1 change: 0 additions & 1 deletion src/js/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ $('#registerBtn').click(function(){
'hasName': hasName
},
success: (data) => {
console.log(data);

}
});
Expand Down
29 changes: 24 additions & 5 deletions src/js/shopCar.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,12 @@ function actionsInTable(data) {
})

}
console.log(deleteallArr);

//删除全部按钮 随便写的,标准情况下该删除数据方式会被K,不能在循环中做删除工作
$('em.goods-delete').on('click', function () {
var res = confirm('是否删除该商品?');
if (res) {
for (var j = 0; j < deleteallArr.length; j++) {
deleteData(deleteallArr[j]);
}
deleteAllData(deleteallArr);
} else {
return;
}
Expand All @@ -178,7 +176,6 @@ function updateDataToDataBase(number, totalprice, id) {
'id': id
},
success: (result) => {
console.log(result);
}
});
}
Expand All @@ -203,4 +200,26 @@ function deleteData(id) {
}
}
});
}
function deleteAllData(idsArr) {
var idstr = "";
for (var i = 0; i < idsArr.length; i++){
idstr += idsArr[i]+",";
}
idstr = idstr.substring(0, idstr.length - 1);

$.ajax({
url: '../php/deleteAllShopCar.php',
type: 'post',
dataType: 'json',
async: false,
data: {
'idstr': idstr
},
success: (data) => {
if (data.code == 0) {
location.reload();
}
}
});
}
17 changes: 17 additions & 0 deletions src/php/deleteAllShopCar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
include "./header.php";
include "./connection.php";

$idstr=$_POST['idstr'];

$sql="DELETE FROM SHOPCAR WHERE ID IN ($idstr)";
$res = mysqli_query($link, $sql);
if($res){
$json = array('code' => 0, 'content' => '删除成功');
echo json_encode($json);
}else{
$json=array('code'=>1,'content'=>'删除失败');
echo json_encode($json);
}

?>
2 changes: 2 additions & 0 deletions src/php/deleteSingleShopCar.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
$json=array('code'=>1,'content'=>'删除失败');
echo json_encode($json);
}

?>

0 comments on commit 9381f54

Please sign in to comment.