admin 管理员组文章数量: 1086019
I have to send a http DELETE request to a server. The type has to be JSON, and the object looks like this:
{ "id": "value"}
My first approach was the following code, but so far it doesn't work:
$http.delete('http://blabla/server/house', {"id": "value"}).success(function(data) {
console.log(data);
//Redirect to index.html
$location.path('/');
});
What would a working solution look like?
I have to send a http DELETE request to a server. The type has to be JSON, and the object looks like this:
{ "id": "value"}
My first approach was the following code, but so far it doesn't work:
$http.delete('http://blabla/server/house', {"id": "value"}).success(function(data) {
console.log(data);
//Redirect to index.html
$location.path('/');
});
What would a working solution look like?
Share Improve this question edited Nov 28, 2016 at 16:50 Rishabh 3,8624 gold badges48 silver badges75 bronze badges asked Apr 15, 2015 at 14:47 AlessandroAlessandro 9253 gold badges17 silver badges33 bronze badges 1-
The syntax is:
$http.delete(url, [config])
, not$http.delete(url, [data])
– Kevin B Commented Apr 15, 2015 at 15:07
3 Answers
Reset to default 4As @KevinB pointed out, config is the second parameter.
var obj = { "id": "value"};
var config = { data: JSON.stringify(obj) };
$http.delete('http://blabla/server/house', config).success(function(data) {
console.log(data);
//Redirect to index.html
$location.path('/');
});
$http({
method: 'DELETE',
url: 'http://blabla/server/house',
data: JSON.stringify({
'id': 'value'
})
}).success(function (results) {
console.log(results);
//Redirect to index.html
$location.path('/');
});
I guess you can just pass the param as part of the query params. Something like this:
var config = {
params: {
yourServerSideParamName: JSON.stringify({'id': 'value' })
}
};
$http.delete('blabla/server/house', config).success(function(data){
$location.path('/');
});
Hope it helps!
本文标签: javascriptHow to send DELETE request to server with Json data using AngularJSStack Overflow
版权声明:本文标题:javascript - How to send DELETE request to server with Json data using AngularJS? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744008342a2517689.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论