d8ta d8ta - 1 year ago 85
AngularJS Question

How to send and array in $http.delete

I want to delete the tag created using http post. here is the code that i have tried.

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.

Answer Source

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!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download