在我的 Django Rest API Famework 中,为了启用 CORS,我正在使用该应用程序:
corsheaders
( django-cors-headers ) 设置:
CORS_ORIGIN_ALLOW_ALL = True
对于 GET
、POST
和 PATCH
工作正常
但是,仅对于DELETE
,我收到此错误:
no access-control-allow-origin header on the requested resource
我正在像这样从 javascript 触发此请求:
data = {oper:'campaigns', req_type:'dc'};
$.ajax({
url: url,
type: "DELETE",
traditional: true,
datatype:"json",
contentType: 'application/json;charset=UTF-8',
data: JSON.stringify(data),
我不明白为什么这种情况只发生在删除!!
最佳答案
这里没有足够的信息(状态代码是什么等...),但请在您的 Ajax 请求上尝试以下操作:
data: {'_method':'delete'},
type: 'POST'
并非所有浏览器都支持 DELETE 方法。
关于javascript - django 删除时没有 access-control-allow-origin header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29426354/