如何使用angularjs $http请求从mysql数据库中删除数据?

时间:2022-08-22 17:42:46

Here is the code

这是代码

        $scope.Delete = function(customer ){

        $http({
        method: 'get',
        url: 'rest/customers',
        data: {customers:customer.custId},

        }).then(function successCallback(response) {
            $scope.customers.splice($scope.customers.indexOf(customer), 1);
        }); 
    }

If I call this function it only deletes the data from the front-end. The data is not getting deleted from mysql table. Can anyone help me with this.

如果我调用这个函数,它只会从前端删除数据。数据不会从mysql表中删除。有人能帮我吗?

2 个解决方案

#1


1  

//try like this..sure it will work
$http.delete('your url' + id).then(function(result){
   if(result.data){
     //your handle code
   }
}, function(err) {
   console.log(err);
});

#2


0  

First, it is not efficient to test api with front end code, you need to set up a postman test to separate your concern, get it working in postman first.

首先,用前端代码测试api是无效的,您需要设置一个postman测试来分离您的关注点,让它先在邮递员工作。

After postman test, you can use $http.delete, sample link is here

在postman测试之后,您可以使用$http.delete,示例链接在这里。

#1


1  

//try like this..sure it will work
$http.delete('your url' + id).then(function(result){
   if(result.data){
     //your handle code
   }
}, function(err) {
   console.log(err);
});

#2


0  

First, it is not efficient to test api with front end code, you need to set up a postman test to separate your concern, get it working in postman first.

首先,用前端代码测试api是无效的,您需要设置一个postman测试来分离您的关注点,让它先在邮递员工作。

After postman test, you can use $http.delete, sample link is here

在postman测试之后,您可以使用$http.delete,示例链接在这里。