我有以下代码:
deleteArticle = function(assetData) {
var defer;
var assetId = assetData.assetId;
var cseService = $resource(CSE_CONFIG.apiBaseUrl + 'articles/' + assetId,{}, {'remove': {method: 'DELETE', isArray: false}});
defer = $q.defer();
$log.info(assetData.data);
cseService.remove(assetData.data, function(results) {
return defer.resolve(results);
}, function(results) {
$log.error('suggestionsService deleteArticle error', results);
return defer.reject(results);
});
return defer.promise;
}
assetsData = {"assetId":12345,"data":{"inappropriate":true,"comment":"这是评论"}}
我使用 express 作为服务器,这是我的路线:
app.delete('/api/v1/articles/:assetId', function (req, res) {
console.log("delete is called for " + req.params.assetId);
console.log(req.body);
for (var i = 0; i < suggestions[0].articles.length; i++) {
var row = suggestions[0].articles[i];
if (row.assetId === req.params.assetId) {
suggestions[0].articles.splice(i,1);
console.log("REMOVED:::::");
console.log(row);
return res.send("OK",200);
}
}
return res.send("BAD Request",400);
});
当我将它发送到服务器时,req.body 不包含assetData.data。所以问题是,如何使用 $resource 和 method=DELETE 发送正文?注意:我使用 Chrome:Postman REST 客户端测试了服务器,它工作正常,但在使用 Angular 时不能正常工作。