1

I would like to send ID to my node server.

but I don't know how to get it server side. The Req is sent. console.log(req.body) returned empty...

Controller:

$scope.remove = function(id) {
    var idstring = JSON.parse(id);
    $http.delete('/contactlist/remove', {data: idstring}).then(function(response){
        $scope.contactlist = $scope.contactlist.filter(function(contact){
            return contact.id !== id;
        })
    });
};

Server:

app.delete('/contactlist/remove', function (req, res) {
    console.log(req.body);
    // connection.query('DELETE FROM contactlist WHERE id = ' + req.body.id, function (error, results, fields) {
    res.json();
    // });
});

Screenshot of DELETE request in chrome: enter image description here

1 Answer 1

1

You can't send data in delete method

so make delete url like /contactlist/remove/3

$http.delete('/contactlist/remove/'+idstring).then(function(response){
        $scope.contactlist = $scope.contactlist.filter(function(contact){
            return contact.id !== id;
        })
    });

On server side

app.delete('/contactlist/remove/:idstring', function (req, res) {
    console.log(req.params.idstring);
    connection.query('DELETE FROM contactlist WHERE id = ' + req.params.idstring, function (error, results, fields) {
    res.json();
    });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.