javascript - Delete database data in angularjs -
when put link on browser worked. but, when clicked on button not working. wrong in code. http://localhost/youtubewebservice/shopcartproductdelete.php?cart_id=6
$scope.delete = function(cart_id, index) { var params = $.param({"cart_id":cart_id}); console.log(cart_id); $http({ headers: {'content-type': 'application/x-www-form-urlencoded'}, url: 'http://localhost/youtubewebservice/shopcartproductdelete.php?cart_id=$cart_id', method: "get", data: params }).success(function(data){ $scope.data.splice(index, 1); }); }
<img src="img/removecart.png" ng-click="delete({{produ.cart_id}}, $index)" style="max-height: 40px;margin-right: 15px;"/>
php code
<?php $con = mysqli_connect("localhost","root","","look4com_lk"); if(isset($_get['cart_id'])){ $cart_id = $_get['cart_id']; $res = "delete l4wlk_cart cart_id='".$cart_id."'"; mysqli_query($con, $res); } echo json_encode($result); ?>
see the documentation of ng-click
it uses expression
.
if template
written in type
column, have written values in double curly braces {{..}}
. since accepts expression, there's no need use double curly braces.
change <img..>
to:
<img src="img/removecart.png" ng-click="delete(produ.cart_id, $index)" style="max-height: 40px;margin-right: 15px;"/>
Comments
Post a Comment