我有函数调用 http.delete 并传递参数标志:
function softDeleteDatasource(datasourceId,flag) {
var url = baseUrl + datasourceId;
return $http.delete(url, {'currentFieldSetFlag':flag});
}
然后我假设我可以用下面的代码得到 req.body。但是,我总是在 console.log
中得到 undefined
。我在 http.post
中使用了完全相同的代码,并且在传递参数时它工作正常。
var bodyParser = require('body-parser');
var jsonParser = bodyParser.json();
router.delete('/:datasourceId', jsonParser, function(req, res) {
console.log(req.body.currentFieldSetFlag);
}
我很困惑为什么同样的代码不能在http.delete
中传递参数?有谁知道怎么通过吗?
最佳答案
HTTP 规范允许 DELETE 上的正文,但一些客户端不发送它们,一些代理/服务器将删除/忽略它们(如果存在)。这应该可以将其作为查询字符串参数传递:
return $http.delete(url, {params: {'currentFieldSetFlag':flag}});
关于javascript - 为什么在 AngularJs 中 http.delete 时我不能传递参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32615816/