Reputation: 167
I want to delete the tag created using http post. here is the code that i have tried.
$http({
method: 'DELETE',
url: '/api/tags',
data: [vm.tags.name]
}).success(function(data) {
console.log('Gets DELETED');
vm.tags.name = data;
}).error(function(data) {
console.log('Does not get DELETED');
});
However this didn't work and it only sends an array with [null]. So is there something i don't see or understand here. I mean, if the POST works it should work the same way with DELETE, right? By the way it shows the log "Gets DELETED" but didn't do so.
Upvotes: 2
Views: 6930
Reputation: 167
I got the solution! In my case HTTP 1.1 was able to send the body, but the header was not able so use the content of JSON. So, by adding headers: {'Content-Type': 'application/json;charset=utf-8'}
to the data: field of the $http.delete
it worked and the array got send.
I hope this helps someone.
Thanks for the answers!
Upvotes: 5
Reputation: 959
Take a look in this answer, if you send something in the body of DELETE is ignored.
You should send in the path like this:
current/path?id=1&id=2&id=3&id=4
It's like the GET method, you are not allowed to send anything in the body.
UPDATE
If you make a request with the URL parameters in the example, you will receive a object like this:
{ id : [1, 2, 3, 4] }
Upvotes: 3