在向 node.js 应用程序发出 DELETE 请求之前,我是否需要设置任何配置?
我可以发出 GET
、POST
或 PUT
请求,但 DELETE
请求不起作用。
DELETE http://localhost:8081/api/1.0/entry
从路由记录器中产生 undefined
,我使用 express 来注册路由。但看起来我什至无法解析 url/动词。
这就是我调用它的方式:
rows.find('a.remove').on('click', function(){
$.ajax({
url: '/api/1.0/entry',
type: 'DELETE'
}).done(function(res){
var row = $(this).parentsUntil('tbody');
row.slideUp();
});
});
样本日志
GET / 200 18ms
GET /author/entry 200 10ms
GET /api/1.0/entry 200 2ms
GET /api/1.0/entry 200 1ms
GET /api/1.0/entry 200 1ms
undefined
最佳答案
希望这能有所帮助:
启用日志记录作为您的第一个中间件,以确保请求进入:
app.use(express.logger());
使用 methodOverride() 中间件:
app.use(express.bodyParser());
app.use(express.methodOverride());//在隐藏字段中查找 DELETE 动词
创建一个 .del() 路由:
app.del('/api/1.0/entry', function(req, res, next) { ... });
关于javascript - Node.JS 中的 HTTP DELETE 动词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14173770/