当前位置: 首页 > 知识库问答 >
问题:

Access-Control-Allog-Methods在预响应中不允许删除方法

欧桐
2023-03-14

我试图创建一个删除ajax请求,但似乎无法使其工作。当我用邮递员制作它时,它就起作用了。下面是我的代码:

这是我用jQuery的.ajax()方法发出的请求:

$.ajax({
    url: imageUrl,
    type: 'DELETE',
    crossDomain: true
});
app.use(function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    next();
});

请求

Request URL:http://original/request/url
Request Method:OPTIONS
Status Code:200 OK
Remote Address:75.126.137.93:80 

请求标头

Accept:*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4,es;q=0.2,gl;q=0.2
Access-Control-Request-Headers:
Access-Control-Request-Method:DELETE
Connection:keep-alive
Host:fs.bvodola.webfactional.com
Origin:http://localhost:3000
Referer:http://localhost:3000/landing/admin/add-page
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36

响应标头

Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept
Access-Control-Allow-Origin:*
Allow:GET,HEAD,DELETE
Connection:keep-alive
Content-Length:15
Content-Type:text/html; charset=utf-8
Date:Sat, 03 Sep 2016 23:34:17 GMT
ETag:W/"f-W+bYAIA7Bs2GwQecFLp1SA"
Server:nginx
X-Powered-By:Express
    null

共有1个答案

吕鹏
2023-03-14

在响应头中添加access-control-allow-methods,并使用您希望允许的方法以逗号分隔:'get、POST、delete...'

 类似资料: