jquery - 使用 xhrFields 时状态代码 = 0 : { withCredentials: true } in jQuery $ajax call with Firefox

标签 jquery ajax firefox cookies cors

我正在使用

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/

相关文章:

jquery - 更改 daterangepicker 中的日期格式

javascript - 为什么 bootstrap 4 modal 没有使用 iframe 显示 navbar ul li 实例?

javascript - 使用 spring 和 thymeleaf 在 post 方法中进行 Ajax 部分刷新

php - 在 Mozilla 的 iframe 上禁用键和鼠标单击

asp.net - Firefox 在 IIS6 上启用摘要式身份验证的每个 HTTP 请求上都要求输入用户名/密码

javascript - 如何使用jquery使用select dropdown获取单选按钮的值

javascript - django 批量删除和添加多对多关系

jquery - 无法读取未定义的属性(读取 'formatDate' )

firefox - 在同一个 Firefox 实例上顺序运行 Selenium 测试

javascript - 在提交数据之前更改选择表单元素中的值