角$删除资源不会派身体前press.js服务器 [英] angular $resource delete won't send body to express.js server
问题描述
惠,
我建立与服务器端angular.js和node.js的(前press.js)的应用程序。
i am building an app with angular.js and node.js (Express.js) on the server side.
由于某种原因,我有处理删除请求的问题。没有身体越来越到服务器端。
for some reason i am having a problem handling a delete request. no body is getting to the server side.
这是我的angular.js资源$ C $ C:
this is my angular.js resource code:
$scope.deleteProject = function(projectName){
var postData = {username: 'name', projectName: projectName};
Project.deleteProject.delete({}, postData,
function(res){
alert('Project Deleted');
},
function(err){
alert(err.data);
});
}
在服务器端,我有这样的:
on the server side i have this:
var deleteProject = function(req, res){
console.log(req.body);
console.log(req.params);
if (req.body.projectName){
//do something
return res.send(200);
}
else
return res.send(400, 'no project name was specified');
}
现在由于某种原因没有身体可言!它是空的。
我已经定义为app.delete的路线。
now for some reason there is no body at all!! it is empty. i have defined the route as app.delete.
如果我改变的Node.js张贴在angular.js路线保存它工作正常。
if i change the route in node.js to post and in angular.js to save it works fine.
我是什么在这里失踪(敲我的头)。
what am i missing here (banging my head).
感谢。
推荐答案
按<一个href=\"http://stackoverflow.com/questions/15159213/$p$ptty-coding-to-send-body-with-delete-request-in-angular-js\">this堆栈溢出问题和 $ HTTP
服务来源$ C $ C ,一个删除
要求使用 $ HTTP
不允许发送数据在请求的主体。 对于删除申请该规范是对请求主体是否应该被允许有些模糊,但角度不支持它。
As per this stack overflow question and the $http
service source code, a DELETE
request using $http
does not allow for data to be sent in the body of the request. The spec for a DELETE request is somewhat vague on whether or not a request body should be allowed, but Angular does not support it.
这允许请求主体的唯一方法是 POST
, PUT
和 PATCH
。所以,问题不在任何地方在code,它在角的请求服务。
The only methods that allow for request bodies are POST
, PUT
, and PATCH
. So the problem is not anywhere in your code, its in Angular's request service.
我的建议是改变你的DELETE请求到PUT和对待它,仿佛它是一个DELETE。
My suggestion would be to change your DELETE request into a PUT and treat it as if it were a DELETE.
这篇关于角$删除资源不会派身体前press.js服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!