jQuery的CORS删除失败jQuery、CORS

2023-09-11 01:26:22 作者:终不敌时光i

我有两个领域:

accounts.example.org app.example.org

现在我想做一个 HTTP删除app.example.org 请求accounts.example.org/session。

Now I want to do a HTTP DELETE request from app.example.org to accounts.example.org/session.

$.ajax({
  url: "http://accounts.example.org/session",
  type: "DELETE"
});

真的没什么不同。从accounts.example.org头,让CORS是:

Nothing really different. Headers from accounts.example.org to allow CORS are:

Access-Control-Allow-Origin: http://app.example.org
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Headers: X-Requested-With, Content-Type

所以AJAX调用现在失败,并告诉我,有一个与CORS头一个问题... 我仔细看一下AJAX选项,发现jQuery的不直接做删除

So the AJAX call fails now and tells me that there is a problem with the CORS headers... I took a closer look at the AJAX options and found that jQuery doesn't directly do a DELETE:

Request URL:http://accounts.example.org/session
Request Method:OPTIONS
Status Code:200 OK
Request Headersview source
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
Access-Control-Request-Headers:origin, accept
Access-Control-Request-Method:DELETE
Connection:keep-alive
Host:accounts.example.org
Origin:http://app.example.org
Referer:http://app.example.org/

是否有人知道这是什么可以吗?

Does somebody know what this can be?

服务器后端的Node.js与前preSS作为框架。

Server Backend is node.js with express as framework.

问候

更新

我现在可以指定问题:

现在的问题是,浏览器确实是选项 把之前的请求删除 GET POST 工作)。这样做是因为浏览器想要做真正的请求前检查CORS政策。出于某种原因,EX preSS不处理此请求(响应报头是空的)。因此,浏览器返回的CORS政策禁止的请求。

The problem is that the browser does an OPTIONS request before PUT and DELETE (GET and POST work). This is done because the browser wants to check the CORS policy before doing the real request. For some reason express doesn't handle this request (the response headers are empty). So the browser returns that the CORS policy forbids the request.

我alread尝试:

设置标题与app.use 与app.all 与app.options

没有反应。听起来,有可能是一个错误......

No reactions. Sounds like that there could be a bug ...

推荐答案

什么浏览器是什么呢?我知道它在镀铬ATLEAST。这是jQuery的网页美国关于PUT和DELETE。

What browser is it? I know it works in chrome atleast. This is what jQuery homepage states about PUT and delete.

的请求的类型,使(POST或GET),默认是GET。   注:其他的HTTP请求方法,例如,PUT和DELETE,也可以是   这里使用的,但它们不支持的所有浏览器。

"The type of request to make ("POST" or "GET"), default is "GET". Note: Other HTTP request methods, such as PUT and DELETE, can also be used here, but they are not supported by all browsers."