【发布时间】:2017-02-14 00:36:09
【问题描述】:
由于 CORS,我无法允许来自我的 API 服务器的 DELETE 请求。
server.js
// enable CORS
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET", "PUT", "POST", "DELETE", "OPTIONS");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
next();
});
我收到一个控制台错误提示:
XMLHttpRequest cannot load http://localhost:8080/api/users/57f5036645c04700128d4ee0. Method DELETE is not allowed by Access-Control-Allow-Methods in preflight response
如何启用DELETE 请求,就像GET、PUT 和POST 请求一样?
【问题讨论】:
-
@UmakantMane 我更新了我的前端请求:
$.ajax({ async: true, crossDomain: true, url: '...', method: 'DELETE', headers: { 'content-type': 'application/x-www-form-urlencoded', 'Authorization': '...' } });,但这并没有帮助 -
@UmakantMane 发表评论而不是建议