我正在使用
xhrFields : {
withCredentials: true
}
在 jQuery $ajax 调用中,以便在我的查询中发送 session cookie。
该调用在我的 apache 日志上给出了正确的状态代码(401/200,具体取决于 cookie 是否设置),但 Firefox 始终收到 status=0(即 $.ajax() 中的错误) 如果我删除此 xhrFields 部分,状态代码正常(但不发送 cookie)
这是我在 Firefox 中使用 xhrFields 设置收到的响应对象:
{"readyState":0,"responseText":"","status":0,"statusText":"error"}
我的 Apache 配置启用了 CORS,并且还允许 Access-Control-Allow-Credentials(以下是相应的 HTTP header )
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
AJAX 调用或网络服务器配置中是否缺少某些内容?
注意:这在 Chrome 中工作得很好
最佳答案
您可能必须比 * 更明确地指定 Access-Control-Allow-Origin header 。
https://developer.mozilla.org/En/HTTP_access_control#Requests_with_credentials说:
Important note: when responding to a credentialed request, server must specify a domain, and cannot use wild carding.
关于jquery - 使用 xhrFields 时状态代码 = 0 : { withCredentials: true } in jQuery $ajax call with Firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11269362/