简体   繁体   English

CORS预检OPTIONS请求返回错误,但仍在发送POST

[英]CORS preflight OPTIONS request returning error, but POST still being sent

I'm making a cross-domain request to an asmx service from my site using jQuery ajax as follows: 我正在使用jQuery ajax从我的站点向asmx服务发出跨域请求,如下所示:

$j.ajax({
  url: svcURL,
  type: "POST",
  data: xml,
  contentType: "text/xml",
  dataType: "text",
  success: function(d) {
    alert(d);
  },
  error: function(a, b, c) {
    alert("error");
  }
});

This POST request is preceded by a preflight OPTIONS request which the service is not configured to deal with currently, so it returns with either a 500 (Internal Server Error) or a 405 (Method Not Allowed) . POST请求之前是预检OPTIONS请求,该服务当前未配置为处理该请求,因此它返回500 (Internal Server Error)405 (Method Not Allowed)

After receiving this error, I would expect the browser to then ignore the POST request and return an error, however: 收到此错误后,我希望浏览器随后忽略POST请求并返回错误,但是:

In Chrome & IE the POST request is still sent (which the service is correctly configured to deal with) and a response is received. 在Chrome和IE中 ,仍然发送POST请求(已正确配置服务以进行处理)并收到响应。

In Firefox the POST just returns an error. 在Firefox中POST仅返回错误。

Could someone explain the reason why this works in Chrome? 有人可以解释为什么该功能可以在Chrome浏览器中使用吗? I would have expected it to behave how Firefox does. 我本来希望它表现出Firefox的功能。

Thanks for any help in advance. 感谢您的任何帮助。

There is a bug in Chrome and WebKit that sends the subsequent request even if the OPTIONS request fails. 即使OPTIONS请求失败,ChromeWebKit中也存在一个错误,错误会发送后续请求。

Firefox follows the CORS spec correctly and cancels the request once the preflight fails. Firefox会正确遵循CORS规范,并且在预检失败后会取消请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM